Files
vms/app/controllers/application_controller.rb
David Böhm abe9267893
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / scan_js (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
Modified authentication with user_signed_in? and current_user
2024-08-25 01:20:55 +02:00

33 lines
764 B
Ruby

class ApplicationController < ActionController::Base
before_action :set_current_request_details
before_action :authenticate
private
def current_user
Current.user || authenticate_user_from_session
end
helper_method :current_user
def authenticate_user_from_session
session_record = Session.find_by_id(cookies.signed[:session_token])
Current.session = session_record
Current.user
end
def user_signed_in?
current_user.present?
end
helper_method :user_signed_in?
def authenticate
unless user_signed_in?
redirect_to sign_in_path
end
end
def set_current_request_details
Current.user_agent = request.user_agent
Current.ip_address = request.ip
end
end