| Module | Login::ControllerIntegration::InstanceMethods |
| In: |
lib/login/controller_integration.rb
|
Methods callable from within actions
Will retrieve the current_user. Will not force a login but simply load the current user if a person is logged in. If you need the user object loaded with extra options (such as eager loading) then create a private method called "user_find_options" on your controller that returns a hash of the find options you want.
This method will also inform the models of the current user if the current user is logged in and the "User" class responds to the class method current_user=. This is a nice way to communciate the current user down to the model level for model-level security. This means you will want to call this method at least once before using the model-level security. Usually you will call it in a before filter. This method is called automatically when authentication_required is applied to an action.
# File lib/login/controller_integration.rb, line 64
64: def current_user
65: try_login if session[:uid].nil?
66: @current_user ||=
67: User.find_by_id(session[:uid], user_find_options) unless
68: session[:uid].blank?
69: User.current_user = @current_user if User.respond_to? :current_user=
70: @current_user
71: end
Will store the current params so that we can return here on successful login. If you want to redirect to the login yourself (perhaps you are applying your own security instead of just determining if the user is logged in) then you will want to call this before issuing your redirect to the login screen.
# File lib/login/controller_integration.rb, line 78
78: def store_return_location
79: session[:return_location] = params
80: end