Files
manyfold/app/controllers/application_controller.rb
T
2024-01-26 10:59:14 +00:00

31 lines
822 B
Ruby

class ApplicationController < ActionController::Base
include Pundit::Authorization
before_action :auto_login_single_user
before_action :authenticate_user!
before_action :check_scan_status
before_action :remember_ordering
def auto_login_single_user
# If there is a single user with no password set,
# then log in automatically as that user.
if User.count == 1 && User.first.encrypted_password == ""
sign_in(:user, User.first)
end
end
def authenticate_admin_user!
authenticate_user!
render plain: "401 Unauthorized", status: :unauthorized unless current_user.admin?
end
def check_scan_status
@scan_in_progress = Delayed::Job.count > 0
end
def remember_ordering
session["order"] ||= "name"
session["order"] = params["order"] if params["order"]
end
end