Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show "Reset password token is invalid" error message immediately on /resource/password/edit #2183

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/controllers/devise/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ def create

# GET /resource/password/edit?reset_password_token=abcdef
def edit
self.resource = resource_class.new
resource.reset_password_token = params[:reset_password_token]
self.resource = resource_class.find_or_initialize_with_error_by(:reset_password_token, params[:reset_password_token])
if resource.errors[:reset_password_token].any?
flash[:error] = resource.errors.full_message(:reset_password_token, resource.errors[:reset_password_token].first)
redirect_to new_user_password_path
end
end

# PUT /resource/password
Expand Down
10 changes: 10 additions & 0 deletions test/integration/recoverable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ def reset_password(options={}, &block)
assert_redirected_to "/users/sign_in"
end

test 'not authenticated user with an invalid reset password token should not be able to visit the edit_user_password page' do
get edit_user_password_path(:reset_password_token => 'something_invalid')
assert_response :redirect
assert_redirected_to "/users/password/new"

get "/users/password/new"
assert_have_selector '#flash_error'
assert_contain /Reset password token(.*)invalid/
end

test 'not authenticated user with invalid reset password token should not be able to change his password' do
user = create_user
reset_password :reset_password_token => 'invalid_reset_password'
Expand Down