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

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

Returns:

  • (Boolean)


38
39
40
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 38

def allowed?
  access_control.allowed?(, request.path_info)
end

#current_accountObject

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 ||= 
end

#logged_in?Boolean

Returns true if current_account is logged and active.

Returns:

  • (Boolean)


11
12
13
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 11

def logged_in?
  !.nil?
end

#login_requiredObject

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 
  unless allowed?
    store_location! if store_location
    access_denied
  end
end

#project_modulesObject

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()
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.

Examples:

set_current_account(Account.authenticate(params[:email], params[:password])


28
29
30
31
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 28

def (=nil)
  session[settings.session_id] =  ? .id : nil
  @current_account = 
end

#store_location!Object

Store in session the env.



65
66
67
# File 'padrino-admin/lib/padrino-admin/helpers/authentication_helpers.rb', line 65

def store_location!
  session[:return_to] = "#{ENV['RACK_BASE_URI']}#{env['REQUEST_URI']}" if env['REQUEST_URI']
end