Skip to content

Commit

Permalink
Save user and token in context on token creation
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Jan 18, 2017
1 parent 294b7d2 commit f55cf8d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/resources/pragma/devise/token/operation/create.rb
Expand Up @@ -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: {
Expand All @@ -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
Expand Down

0 comments on commit f55cf8d

Please sign in to comment.