1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/controllers/concerns/authentication.rb

40 lines
682 B
Ruby
Raw Normal View History

module Authentication
extend ActiveSupport::Concern
included do
2024-04-03 10:35:55 -04:00
before_action :authenticate_user!
end
class_methods do
def skip_authentication(**options)
skip_before_action :authenticate_user!, **options
end
end
private
def authenticate_user!
2024-02-05 10:36:46 +11:00
if user = User.find_by(id: session[:user_id])
Current.user = user
else
redirect_to new_session_url
end
end
def login(user)
Current.user = user
reset_session
session[:user_id] = user.id
set_last_login_at
end
def logout
Current.user = nil
reset_session
end
def set_last_login_at
Current.user.update(last_login_at: DateTime.now)
end
end