mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 15:19:38 +02:00
* Minimal code style enforcement * Formatting and lint code updates (no change in functionality)
39 lines
722 B
Ruby
39 lines
722 B
Ruby
module Authentication
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
before_action :authenticate_user!
|
|
end
|
|
|
|
class_methods do
|
|
def skip_authentication(**options)
|
|
skip_before_action :authenticate_user!, **options
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def authenticate_user!
|
|
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
|