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

Support alternate sign in error message when email record does not exist #2147

Merged
merged 3 commits into from Nov 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -19,6 +19,7 @@ en:
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
invalid: 'Invalid email or password.'
invalid_email: 'Invalid email or password.'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'Your account was not activated yet.'
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/strategies/database_authenticatable.rb
Expand Up @@ -6,7 +6,7 @@ module Strategies
class DatabaseAuthenticatable < Authenticatable
def authenticate!
resource = valid_password? && mapping.to.find_for_database_authentication(authentication_hash)
return fail(:invalid) unless resource
return fail(:invalid_email) unless resource

if validate(resource){ resource.valid_password?(password) }
resource.after_database_authentication
Expand Down
12 changes: 7 additions & 5 deletions test/integration/database_authenticatable_test.rb
Expand Up @@ -53,12 +53,14 @@ class DatabaseAuthenticationTest < ActionController::IntegrationTest
end

test 'sign in with invalid email should return to sign in form with error message' do
sign_in_as_admin do
fill_in 'email', :with => 'wrongemail@test.com'
end
store_translations :en, :devise => { :failure => { :admin => { :invalid_email => 'Invalid email address' } } } do
sign_in_as_admin do
fill_in 'email', :with => 'wrongemail@test.com'
end

assert_contain 'Invalid email or password'
assert_not warden.authenticated?(:admin)
assert_contain 'Invalid email address'
assert_not warden.authenticated?(:admin)
end
end

test 'sign in with invalid pasword should return to sign in form with error message' do
Expand Down