Module: TkhAuthenticationActionControllerExtension::InstanceMethods

Defined in:
lib/tkh_authentication/tkh_authentication_action_controller_extension.rb

Instance Method Summary collapse

Instance Method Details

#administrator?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/tkh_authentication/tkh_authentication_action_controller_extension.rb', line 25

def administrator?
  current_user && current_user.admin?
end

#authenticateObject



11
12
13
14
15
16
# File 'lib/tkh_authentication/tkh_authentication_action_controller_extension.rb', line 11

def authenticate
  if current_user.nil?
    session[:target_page] = request.url
    redirect_to , alert: t('authentication.warning.login_needed')
  end
end

#authenticate_with_adminObject



18
19
20
21
22
23
# File 'lib/tkh_authentication/tkh_authentication_action_controller_extension.rb', line 18

def authenticate_with_admin
  unless administrator?
    session[:target_page] = request.url if session[:target_page].nil?
    redirect_to safe_root_url, alert: t('authentication.warning.restricted_access')
  end
end

#current_userObject



7
8
9
# File 'lib/tkh_authentication/tkh_authentication_action_controller_extension.rb', line 7

def current_user
  @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
end