summaryrefslogtreecommitdiff
path: root/users/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/controllers')
-rw-r--r--users/app/controllers/application_controller.rb14
-rw-r--r--users/app/controllers/sessions_controller.rb7
2 files changed, 15 insertions, 6 deletions
diff --git a/users/app/controllers/application_controller.rb b/users/app/controllers/application_controller.rb
new file mode 100644
index 0000000..64e1a55
--- /dev/null
+++ b/users/app/controllers/application_controller.rb
@@ -0,0 +1,14 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ private
+
+ def current_user
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
+ end
+ helper_method :current_user
+
+ def authorize
+ redirect_to login_url, alert: "Not authorized" if current_user.nil?
+ end
+end
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb
index 284c0e2..4a1107d 100644
--- a/users/app/controllers/sessions_controller.rb
+++ b/users/app/controllers/sessions_controller.rb
@@ -8,19 +8,15 @@ class SessionsController < ApplicationController
def create
@user = User.find_by_param(params[:login])
session[:handshake] = @user.initialize_auth(params['A'].hex)
- User.current = @user #?
render :json => session[:handshake]
rescue RECORD_NOT_FOUND
render :json => {:errors => {:login => ["unknown user"]}}
end
def update
- # TODO: validate the id belongs to the session
- @user = User.find_by_param(params[:id])
@srp_session = session.delete(:handshake)
- @srp_session.authenticate!(params[:client_auth].hex)
+ @user = @srp_session.authenticate!(params[:client_auth].hex)
session[:user_id] = @user.id
- User.current = @user #?
render :json => @srp_session
rescue WRONG_PASSWORD
session[:handshake] = nil
@@ -29,7 +25,6 @@ class SessionsController < ApplicationController
def destroy
session[:user_id] = nil
- User.current = nil #?
redirect_to root_path
end
end