Module: UcbRailsUser::Concerns::ControllerMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- HomeController
- Defined in:
- app/controllers/ucb_rails_user/concerns/controller_methods.rb
Instance Method Summary collapse
-
#current_ldap_person ⇒ UCB::LDAP::Person?
Returns an instance of UCB::LDAP::Person if there is a logged in user.
- #current_user ⇒ Object
- #ensure_admin_user ⇒ Object
-
#ensure_authenticated_user ⇒ nil
Before filter that redirects redirects to
login_url
unless user is logged in. - #log_request ⇒ Object
-
#logged_in? ⇒ true, false
Returns
true
if there is a logged in user. - #logged_in_user ⇒ Object
- #not_authorized! ⇒ Object
- #not_authorized_unless(condition) ⇒ Object
- #remove_user_settings ⇒ Object
- #superuser? ⇒ Boolean
- #user_session_manager ⇒ Object
Instance Method Details
#current_ldap_person ⇒ UCB::LDAP::Person?
Returns an instance of UCB::LDAP::Person if there is a logged in user
53 54 55 56 57 58 59 60 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 53 def current_ldap_person if logged_in? @current_ldap_person ||= begin logger.debug 'recalc of current_ldap_person' user_session_manager.people_ou_entry(session[:uid]) end end end |
#current_user ⇒ Object
28 29 30 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 28 def current_user logged_in_user&.impersonation_target || logged_in_user end |
#ensure_admin_user ⇒ Object
62 63 64 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 62 def ensure_admin_user superuser? or end |
#ensure_authenticated_user ⇒ nil
Before filter that redirects redirects to login_url
unless user is logged in
69 70 71 72 73 74 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 69 def ensure_authenticated_user unless session.has_key?(:uid) session[:original_url] = request.env['REQUEST_URI'] redirect_to login_url end end |
#log_request ⇒ Object
40 41 42 43 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 40 def log_request UcbRailsUser::UserSessionManager::Base.current_user = current_user user_session_manager.log_request(current_user) end |
#logged_in? ⇒ true, false
Returns true
if there is a logged in user
36 37 38 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 36 def logged_in? logged_in_user.present? end |
#logged_in_user ⇒ Object
21 22 23 24 25 26 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 21 def logged_in_user @logged_in_user ||= begin logger.debug 'recalc of logged_in_user' user_session_manager&.current_user(session[:uid]) end end |
#not_authorized! ⇒ Object
86 87 88 89 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 86 def render plain: "Not Authorized", status: 401 return false end |
#not_authorized_unless(condition) ⇒ Object
91 92 93 94 95 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 91 def (condition) unless condition end end |
#remove_user_settings ⇒ Object
45 46 47 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 45 def remove_user_settings UcbRailsUser::UserSessionManager::Base.current_user = nil end |
#superuser? ⇒ Boolean
17 18 19 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 17 def superuser? current_user.try(:superuser?) end |
#user_session_manager ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'app/controllers/ucb_rails_user/concerns/controller_methods.rb', line 76 def user_session_manager @user_session_manager ||= begin logger.debug "creating new user_session_manager" klass = UcbRailsUser[:user_session_manager] || UcbRailsUser::UserSessionManager::ActiveInUserTable klass.to_s.classify.constantize.new end rescue NameError raise "Could not find UcbRailsUser user_session_manager: #{klass}" end |