Module: JumpIn::Authentication
- Defined in:
- lib/jump_in/authentication.rb,
lib/jump_in/authentication/cookies.rb,
lib/jump_in/authentication/session.rb
Defined Under Namespace
Modules: ClassMethods, Persistence
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_by_strategy(user:, auth_params:) ⇒ Object
-
#current_user ⇒ Object
HELPER METHODS.
-
#jump_in(user:, **auth_params) ⇒ Object
LOGGING IN.
-
#jump_out ⇒ Object
LOGGING OUT.
- #logged_in? ⇒ Boolean
- #login(user:) ⇒ Object
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/jump_in/authentication.rb', line 6 def self.included(base) base.extend(ClassMethods) base.send :helper_method, :current_user, :logged_in? if base.respond_to? :helper_method base.const_set('GET_CURRENT_USER', []) const_set('APP_MAIN_CONTROLLER', base) end |
Instance Method Details
#authenticate_by_strategy(user:, auth_params:) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/jump_in/authentication.rb', line 24 def authenticate_by_strategy(user:, auth_params:) if strategy = detected_strategy(user: user, auth_params: auth_params) strategy.authenticate_user else false end end |
#current_user ⇒ Object
HELPER METHODS
48 49 50 51 |
# File 'lib/jump_in/authentication.rb', line 48 def current_user return @current_user if defined?(@current_user) @current_user = get_current_user end |
#jump_in(user:, **auth_params) ⇒ Object
LOGGING IN
15 16 17 18 19 20 21 22 |
# File 'lib/jump_in/authentication.rb', line 15 def jump_in(user:, **auth_params) if !logged_in? && authenticate_by_strategy(user: user, auth_params: auth_params) login(user: user) else return false end end |
#jump_out ⇒ Object
LOGGING OUT
41 42 43 44 |
# File 'lib/jump_in/authentication.rb', line 41 def jump_out self.class::ON_LOGOUT.each { |on_logout| send(on_logout) } true end |
#logged_in? ⇒ Boolean
53 54 55 |
# File 'lib/jump_in/authentication.rb', line 53 def logged_in? !!current_user end |
#login(user:) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/jump_in/authentication.rb', line 32 def login(user:) self.class::ON_LOGIN.each do |on_login| send(on_login, user: user) end true end |