Module: UffizziCore::AuthManagement
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/uffizzi_core/auth_management.rb
Instance Method Summary collapse
- #auth_token ⇒ Object
- #authenticate_request! ⇒ Object
- #current_user ⇒ Object
- #current_user_id ⇒ Object
- #sign_in(user) ⇒ Object
- #sign_out ⇒ Object
- #signed_in? ⇒ Boolean
Instance Method Details
#auth_token ⇒ Object
20 21 22 23 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 20 def auth_token header = request.headers['Authorization'] header&.split(' ')&.last end |
#authenticate_request! ⇒ Object
36 37 38 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 36 def authenticate_request! current_user ? true : head(:unauthorized) end |
#current_user ⇒ Object
16 17 18 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 16 def current_user @current_user ||= UffizziCore::User.find_by(id: current_user_id) end |
#current_user_id ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 25 def current_user_id return session[:user_id] if session[:user_id].present? return unless auth_token.present? decoded_token = UffizziCore::TokenService.decode(auth_token) return unless decoded_token return if decoded_token.first['expires_at'] < DateTime.now decoded_token.first['user_id'] end |
#sign_in(user) ⇒ Object
4 5 6 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 4 def sign_in(user) session[:user_id] = user.id end |
#sign_out ⇒ Object
8 9 10 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 8 def sign_out session[:user_id] = @current_user = nil end |
#signed_in? ⇒ Boolean
12 13 14 |
# File 'app/controllers/concerns/uffizzi_core/auth_management.rb', line 12 def signed_in? session[:user_id].present? && current_user.present? end |