diff options
Diffstat (limited to 'users/app/controllers/sessions_controller.rb')
-rw-r--r-- | users/app/controllers/sessions_controller.rb | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/users/app/controllers/sessions_controller.rb b/users/app/controllers/sessions_controller.rb index 284c0e2..bc910b5 100644 --- a/users/app/controllers/sessions_controller.rb +++ b/users/app/controllers/sessions_controller.rb @@ -3,33 +3,24 @@ class SessionsController < ApplicationController skip_before_filter :verify_authenticity_token def new + @session = Session.new + if authentication_errors + @errors = authentication_errors + render :status => 422 + end end 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"]}} + authenticate! 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) - session[:user_id] = @user.id - User.current = @user #? - render :json => @srp_session - rescue WRONG_PASSWORD - session[:handshake] = nil - render :json => {:errors => {"password" => ["wrong password"]}} + authenticate! + render :json => session.delete(:handshake) end def destroy - session[:user_id] = nil - User.current = nil #? + logout redirect_to root_path end end |