Module: Kadmin::Concerns::AuthorizedUser
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController, AuthConstraint
- Defined in:
- app/controllers/kadmin/concerns/authorized_user.rb
before_action collapse
-
#authorize ⇒ Object
Add as a before_action whenever you wish to authorize a user for a particular resource.
View Helpers collapse
-
#authorized_user ⇒ Kadmin::Auth::User
Instance of the user identified by current_user.
-
#current_user ⇒ String
The current user identifier.
Helpers collapse
-
#authorized? ⇒ Boolean
True if the user is authorized in, false otherwise.
-
#logged_in? ⇒ Boolean
True if the user is logged in, false otherwise.
Instance Method Details
#authorize ⇒ Object
Add as a before_action whenever you wish to authorize a user for a particular resource. The app provided user model will perform authorization of the resource.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 22 def if Kadmin::Auth.config.enabled? if logged_in? unless redirect_to Kadmin::Engine.routes.url_helpers. end else redirect_to Kadmin::Engine.routes.url_helpers.auth_login_path(origin: request.fullpath) end end end |
#authorized? ⇒ Boolean
Returns true if the user is authorized in, false otherwise.
60 61 62 |
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 60 def return &.(request) end |
#authorized_user ⇒ Kadmin::Auth::User
Returns instance of the user identified by current_user.
45 46 47 |
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 45 def return Kadmin::Auth.users.get(current_user) end |
#current_user ⇒ String
Returns the current user identifier. Historically called current_user.
39 40 41 |
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 39 def current_user Kadmin::Auth.test_user || session[Kadmin::AuthController::SESSION_KEY] end |
#logged_in? ⇒ Boolean
Returns true if the user is logged in, false otherwise.
54 55 56 |
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 54 def logged_in? return current_user.present? end |