Class: Trestle::Auth::Backends::Basic
- Defined in:
- lib/trestle/auth/backends/basic.rb
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the current logged in user (after #authentication).
Attributes inherited from Base
#controller, #cookies, #request, #session
Instance Method Summary collapse
-
#authenticate ⇒ Object
Authenticates a user from the session or cookie.
-
#authenticate! ⇒ Object
Authenticates a user from a login form request.
-
#logged_in? ⇒ Boolean
Checks if there is a logged in user.
-
#login!(user) ⇒ Object
Stores the given user in the session as logged in.
-
#logout! ⇒ Object
Logs out the current user.
Methods inherited from Base
#initialize, #previous_location, #scope, #store_location
Constructor Details
This class inherits a constructor from Trestle::Auth::Backends::Base
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the current logged in user (after #authentication).
6 7 8 |
# File 'lib/trestle/auth/backends/basic.rb', line 6 def user @user end |
Instance Method Details
#authenticate ⇒ Object
Authenticates a user from the session or cookie. Called on each request via a before_action.
20 21 22 |
# File 'lib/trestle/auth/backends/basic.rb', line 20 def authenticate @user = find_authenticated_user || find_remembered_user end |
#authenticate! ⇒ Object
Authenticates a user from a login form request.
9 10 11 12 13 14 15 16 17 |
# File 'lib/trestle/auth/backends/basic.rb', line 9 def authenticate! params = login_params if user = Trestle.config.auth.authenticate(params) login!(user) remember_me! if Trestle.config.auth.remember.enabled && params[:remember_me] user end end |
#logged_in? ⇒ Boolean
Checks if there is a logged in user.
25 26 27 |
# File 'lib/trestle/auth/backends/basic.rb', line 25 def logged_in? !!user end |
#login!(user) ⇒ Object
Stores the given user in the session as logged in.
30 31 32 33 |
# File 'lib/trestle/auth/backends/basic.rb', line 30 def login!(user) session[:trestle_user] = user.id @user = user end |
#logout! ⇒ Object
Logs out the current user.
36 37 38 39 40 41 42 43 44 |
# File 'lib/trestle/auth/backends/basic.rb', line 36 def logout! if logged_in? && Trestle.config.auth.remember.enabled Trestle.config.auth.remember.forget_me(user) .delete(:trestle_remember_token) end session.delete(:trestle_user) @user = nil end |