Module: Padrino::Admin::Helpers::AuthenticationHelpers
- Defined in:
- padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb
Overview
Common helpers used for authorization within an application.
Instance Method Summary collapse
-
#allowed? ⇒ Boolean
Returns true if the
current_account
is allowed to see the requested path. -
#current_account ⇒ Object
Returns the current_account, it’s an instance of Account model.
-
#logged_in? ⇒ Boolean
Returns true if
current_account
is logged and active. -
#login_required ⇒ Object
Returns a helper useful in a
before_filter
for check if an account are:logged_in?
andallowed?
. -
#project_modules ⇒ Object
Returns project modules for the current account.
-
#redirect_back_or_default(default) ⇒ Object
Redirect the account to the page that requested an authentication or if the account is not allowed/logged return it to a default page.
-
#set_current_account(account = nil) ⇒ Object
Override the current_account, you must provide an instance of Account model.
- #store_location! ⇒ Object
Instance Method Details
#allowed? ⇒ Boolean
Returns true if the current_account
is allowed to see the requested path.
For configure this role please refer to: Padrino::Admin::AccessControl::Base
38 39 40 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 38 def allowed? access_control.allowed?(current_account, request.path_info) end |
#current_account ⇒ Object
Returns the current_account, it’s an instance of Account model.
18 19 20 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 18 def current_account @current_account ||= login_from_session end |
#logged_in? ⇒ Boolean
Returns true if current_account
is logged and active.
11 12 13 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 11 def logged_in? !current_account.nil? end |
#login_required ⇒ Object
Returns a helper useful in a before_filter
for check if an account are: logged_in?
and allowed?
By default this method is used in Admin Apps.
55 56 57 58 59 60 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 55 def login_required unless allowed? store_location! if store_location access_denied end end |
#project_modules ⇒ Object
Returns project modules for the current account.
45 46 47 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 45 def project_modules access_control.project_modules(current_account) end |
#redirect_back_or_default(default) ⇒ Object
Redirect the account to the page that requested an authentication or if the account is not allowed/logged return it to a default page.
73 74 75 76 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 73 def redirect_back_or_default(default) return_to = session.delete(:return_to) redirect(return_to || default) end |
#set_current_account(account = nil) ⇒ Object
Override the current_account, you must provide an instance of Account model.
28 29 30 31 |
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 28 def set_current_account(account=nil) session[settings.session_id] = account ? account.id : nil @current_account = account end |