Module: Godmin::Authentication

Extended by:
ActiveSupport::Concern
Defined in:
lib/godmin/authentication.rb,
lib/godmin/authentication/user.rb,
lib/godmin/authentication/sessions_controller.rb

Defined Under Namespace

Modules: SessionsController, User

Instance Method Summary collapse

Instance Method Details

#admin_userObject



25
26
27
28
29
# File 'lib/godmin/authentication.rb', line 25

def admin_user
  if session[:admin_user_id]
    @admin_user ||= admin_user_class.find_by(id: session[:admin_user_id])
  end
end

#admin_user_classObject

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/godmin/authentication.rb', line 21

def admin_user_class
  raise NotImplementedError, "Must define the admin user class"
end

#admin_user_signed_in?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/godmin/authentication.rb', line 31

def admin_user_signed_in?
  admin_user.present?
end

#authenticate_admin_userObject



15
16
17
18
19
# File 'lib/godmin/authentication.rb', line 15

def authenticate_admin_user
  unless admin_user_signed_in? || controller_name == "sessions"
    redirect_to new_session_path, alert: "Authentication needed"
  end
end