hackatime/app/controllers/application_controller.rb

24 lines
588 B
Ruby

class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
helper_method :current_user, :user_signed_in?
private
def current_user
@current_user ||= User.find_by(id: session[:user_id]) if session[:user_id]
end
def user_signed_in?
!!current_user
end
def authenticate_user!
unless user_signed_in?
redirect_to root_path, alert: "Please sign in first!"
end
end
end