From f55cf8de68a1b492cab842b21d885901b77fc613 Mon Sep 17 00:00:00 2001 From: Alessandro Desantis Date: Wed, 18 Jan 2017 14:59:19 +0100 Subject: [PATCH] Save user and token in context on token creation --- .../pragma/devise/token/operation/create.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/resources/pragma/devise/token/operation/create.rb b/app/resources/pragma/devise/token/operation/create.rb index 3112be8..66ef19d 100644 --- a/app/resources/pragma/devise/token/operation/create.rb +++ b/app/resources/pragma/devise/token/operation/create.rb @@ -15,9 +15,9 @@ def contract_klass def call validate! OpenStruct.new - user = self.class.model_klass.find_for_authentication(email: params[:email]) + context.user = self.class.model_klass.find_for_authentication(email: params[:email]) - unless user && user.valid_password?(params[:password]) + unless context.user && context.user.valid_password?(params[:password]) respond_with!( status: :unprocessable_entity, resource: { @@ -27,21 +27,21 @@ def call ) end - unless user.active_for_authentication? + unless context.user.active_for_authentication? respond_with!( status: :unauthorized, resource: { - error_type: user.inactive_message, + error_type: context.user.inactive_message, error_message: I18n.t( - "devise.failure.#{user.inactive_message}", + "devise.failure.#{context.user.inactive_message}", default: 'You cannot authenticate at this moment.' ) } ) end - token = Knock::AuthToken.new payload: { sub: user.id } - respond_with status: :created, resource: { token: token.token } + context.token = Knock::AuthToken.new payload: { sub: context.user.id } + respond_with status: :created, resource: { token: context.token.token } end end end