Sha256: ec251562f1e983562b7b657002147c3d37485f619b685339bbc16aec1aa6a3ec
Contents?: true
Size: 834 Bytes
Versions: 5
Compression:
Stored size: 834 Bytes
Contents
module TkhAuthenticationActionControllerExtension def self.included(base) base.send(:include, InstanceMethods) end module InstanceMethods def current_user @current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token] end def authenticate if current_user.nil? session[:target_page] = request.url redirect_to login_url, alert: t('authentication.warning.login_needed') end end def authenticate_with_admin unless current_user && current_user.admin? session[:target_page] = request.url if session[:target_page].nil? redirect_to safe_root_url, alert: t('authentication.warning.restricted_access') end end private def safe_root_url defined?(root_url) ? root_url : '/' end end end
Version data entries
5 entries across 5 versions & 1 rubygems