diff options
author | jessib <jessib@riseup.net> | 2013-08-27 12:18:35 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-08-27 12:18:35 -0700 |
commit | dc41ae0a3fb0a137e716d8ec63084b0ec3a7299b (patch) | |
tree | c09fef161f105e7c03c35d1edcb2d257144cb97d /users/app/controllers/controller_extension/authentication.rb | |
parent | a87c750d1f12f15272beb117f8ee12ab711cc6d1 (diff) | |
parent | e481b8cbc05a858674a59ef36d695973622f6b3a (diff) |
Merge branch 'master' into billing_with_tests
Diffstat (limited to 'users/app/controllers/controller_extension/authentication.rb')
-rw-r--r-- | users/app/controllers/controller_extension/authentication.rb | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/users/app/controllers/controller_extension/authentication.rb b/users/app/controllers/controller_extension/authentication.rb index 5fac884..dca3664 100644 --- a/users/app/controllers/controller_extension/authentication.rb +++ b/users/app/controllers/controller_extension/authentication.rb @@ -7,28 +7,8 @@ module ControllerExtension::Authentication helper_method :current_user, :logged_in?, :admin? end - def authentication_errors - 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 - message = strategy.message - # in case we get back the default message to fail! - message.respond_to?(:inject) ? message : { base: message } - else - { login: :all_strategies_failed } - end - end - - def attempted_login? - request.env['warden.options'] && - request.env['warden.options'][:attempted_path] + def current_user + @current_user ||= token_authenticate || warden.user end def logged_in? @@ -62,4 +42,27 @@ module ControllerExtension::Authentication access_denied unless admin? end + def authentication_errors + 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 + message = strategy.message + # in case we get back the default message to fail! + message.respond_to?(:inject) ? message : { base: message } + else + { login: :all_strategies_failed } + end + end + + def attempted_login? + request.env['warden.options'] && + request.env['warden.options'][:attempted_path] + end end |