Skip to content

Commit

Permalink
Merge pull request lynndylanhurley#1095 from TylerRockwell/lockout-me…
Browse files Browse the repository at this point in the history
…ssage

Return locked out message from sessions controller when resource is locked
  • Loading branch information
Maicol Bentancor authored Feb 26, 2018
2 parents e45539e + bb79a2b commit 835a147
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app/controllers/devise_token_auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def create
if @resource && valid_params?(field, q_value) && (!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
valid_password = @resource.valid_password?(resource_params[:password])
if (@resource.respond_to?(:valid_for_authentication?) && !@resource.valid_for_authentication? { valid_password }) || !valid_password
render_create_error_bad_credentials
return
return render_create_error_bad_credentials
end
@client_id, @token = @resource.create_token
@resource.save
Expand All @@ -34,7 +33,11 @@ def create

render_create_success
elsif @resource && !(!@resource.respond_to?(:active_for_authentication?) || @resource.active_for_authentication?)
render_create_error_not_confirmed
if @resource.respond_to?(:locked_at) && @resource.locked_at
render_create_error_account_locked
else
render_create_error_not_confirmed
end
else
render_create_error_bad_credentials
end
Expand Down Expand Up @@ -102,6 +105,10 @@ def render_create_error_not_confirmed
render_error(401, I18n.t("devise_token_auth.sessions.not_confirmed", email: @resource.email))
end

def render_create_error_account_locked
render_error(401, I18n.t("devise.mailer.unlock_instructions.account_lock_msg"))
end

def render_create_error_bad_credentials
render_error(401, I18n.t("devise_token_auth.sessions.bad_credentials"))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def @controller.reset_session

test 'response should contain errors' do
assert @data['errors']
assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.not_confirmed', email: @locked_user.email)]
assert_equal @data['errors'], [I18n.t('devise.mailer.unlock_instructions.account_lock_msg')]
end
end

Expand Down

0 comments on commit 835a147

Please sign in to comment.