diff options
author | jessib <jessib@riseup.net> | 2013-08-27 11:22:52 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-08-27 11:22:52 -0700 |
commit | e481b8cbc05a858674a59ef36d695973622f6b3a (patch) | |
tree | 8a20143ce831d71076a8c3913664b3a67742ed6b /users/app/controllers/controller_extension/authentication.rb | |
parent | 441db4736e0cd003caf9c8f7b3fbdb1ffa72b969 (diff) | |
parent | fdf9c5f9ea605020ea371de8e221efe8e5d5ba32 (diff) |
Merge pull request #72 from azul/feature/token-based-auth
Feature: Token based auth
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 |