Common helpers used for authorization within an application.
Returns true if the current_account
is allowed to see the
requested path.
For configure this role please refer to: +Padrino::Admin::AccessControl::Base+
# File lib/padrino-admin/helpers/authentication_helpers.rb, line 38 def allowed? access_control.allowed?(current_account, request.path_info) end
Returns the #current_account, it’s an instance of Account model.
# File lib/padrino-admin/helpers/authentication_helpers.rb, line 18 def current_account @current_account ||= login_from_session end
Returns true if current_account
is logged and active.
# File lib/padrino-admin/helpers/authentication_helpers.rb, line 11 def logged_in? !current_account.nil? end
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.
# File lib/padrino-admin/helpers/authentication_helpers.rb, line 55 def login_required unless allowed? store_location! if store_location access_denied end end
Returns project modules for the current account.
# File lib/padrino-admin/helpers/authentication_helpers.rb, line 45 def project_modules access_control.project_modules(current_account) end
Redirect the account to the page that requested an authentication or if the account is not allowed/logged return it to a default page.
# File 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
Override the #current_account, you must provide an instance of Account model.
@example
set_current_account(Account.authenticate(params[:email], params[:password])
# File 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