diff options
author | Azul <azul@leap.se> | 2013-04-02 16:56:11 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-04-02 16:56:11 +0200 |
commit | d781dbdd61d1d24ec4828859a28815b55310154d (patch) | |
tree | 1e2deca8e62aa804b2babe38f9780089c88f38ff /users/app/controllers | |
parent | 62c48c5a14ea0c1221216c3e40eb82ef594f2771 (diff) |
send more meaningful error message on completely failed login attempt
Diffstat (limited to 'users/app/controllers')
-rw-r--r-- | users/app/controllers/controller_extension/authentication.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb index f2184d9..f0a6564 100644 --- a/users/app/controllers/controller_extension/authentication.rb +++ b/users/app/controllers/controller_extension/authentication.rb @@ -8,13 +8,27 @@ module ControllerExtension::Authentication end def authentication_errors - return unless errors = warden.winning_strategy.try(:message) + return unless attempted_login? + errors = get_warden_errors errors.inject({}) do |translated,err| translated[err.first] = I18n.t(err.last) translated end end + def get_warden_errors + if strategy = warden.winning_strategy + strategy.message + else + { login: :all_strategies_failed } + end + end + + def attempted_login? + request.env['warden.options'] && + request.env['warden.options'][:attempted_path] + end + def logged_in? !!current_user end |