Module: Maquina::Authenticate
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/maquina/authenticate.rb
Overview
A Rails controller concern that handles user authentication. Provides methods for checking authentication status, managing sessions, and controlling access to actions.
Usage
class ApplicationController < ActionController::Base
include Maquina::Authenticate
end
Instance Method Summary collapse
-
#after_authentication_url ⇒ Object
Returns the URL to redirect to after successful authentication.
-
#authenticated? ⇒ Boolean
(also: #signed_in?)
Returns whether there is a signed in user.
-
#current_user ⇒ Object
Returns the currently signed in user or nil.
-
#require_authentication ⇒ Object
Ensures user is authenticated before proceeding.
Instance Method Details
#after_authentication_url ⇒ Object
Returns the URL to redirect to after successful authentication
after_authentication_url # => "http://example.com/dashboard"
52 53 54 |
# File 'app/controllers/concerns/maquina/authenticate.rb', line 52 def after_authentication_url session.delete(:return_to_after_authenticating) || root_url end |
#authenticated? ⇒ Boolean Also known as: signed_in?
Returns whether there is a signed in user
authenticated? # => true
35 36 37 |
# File 'app/controllers/concerns/maquina/authenticate.rb', line 35 def authenticated? Maquina::Current.signed_in? end |
#current_user ⇒ Object
Returns the currently signed in user or nil
current_user # => #<User id: 1, email: "[email protected]">
44 45 46 |
# File 'app/controllers/concerns/maquina/authenticate.rb', line 44 def current_user Maquina::Current.user end |
#require_authentication ⇒ Object
Ensures user is authenticated before proceeding. Redirects to login if no valid session exists.
59 60 61 |
# File 'app/controllers/concerns/maquina/authenticate.rb', line 59 def require_authentication load_session || request_authentication end |