completed SMS gateway project
This commit is contained in:
30
app/controllers/admin/base_controller.rb
Normal file
30
app/controllers/admin/base_controller.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module Admin
|
||||
class BaseController < ActionController::Base
|
||||
include Pagy::Backend
|
||||
|
||||
# Enable session and flash for admin controllers
|
||||
# (needed because the app is in API-only mode)
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
layout "admin"
|
||||
before_action :require_admin
|
||||
|
||||
private
|
||||
|
||||
def current_admin
|
||||
@current_admin ||= AdminUser.find_by(id: session[:admin_id]) if session[:admin_id]
|
||||
end
|
||||
helper_method :current_admin
|
||||
|
||||
def logged_in?
|
||||
current_admin.present?
|
||||
end
|
||||
helper_method :logged_in?
|
||||
|
||||
def require_admin
|
||||
unless logged_in?
|
||||
redirect_to admin_login_path, alert: "Please log in to continue"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user