module TkhAuthenticationActionControllerExtension::InstanceMethods

Public Instance Methods

administrator?() click to toggle source
# File lib/tkh_authentication/tkh_authentication_action_controller_extension.rb, line 25
def administrator?
  current_user && current_user.admin?
end
authenticate() click to toggle source
# 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 login_url, alert: t('authentication.warning.login_needed')
  end
end
authenticate_with_admin() click to toggle source
# 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_user() click to toggle source
# 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

Private Instance Methods

safe_root_url() click to toggle source
# File lib/tkh_authentication/tkh_authentication_action_controller_extension.rb, line 31
def safe_root_url
  defined?(root_url) ? root_url : '/'
end