Class: Admin::SessionsController

Inherits:
AdminController show all
Defined in:
app/controllers/admin/sessions_controller.rb

Instance Attribute Summary

Attributes included from PagesCore::Authentication

#current_user

Instance Method Summary collapse

Methods inherited from PagesCore::AdminController

#redirect, underscore

Methods included from PagesCore::StaticCacheController

#disable_static_cache!, #static_cached?

Methods included from PagesCore::PoliciesHelper

#policy, #verify_policy, #verify_policy_with_proc

Methods included from PagesCore::ProcessTitler

inc_number_of_requests, original_title

Methods included from PagesCore::LocalesHelper

#content_locale

Methods included from PagesCore::ErrorRenderer

#render_error

Methods included from PagesCore::Authentication

#authenticate!, #deauthenticate!, #logged_in?

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/admin/sessions_controller.rb', line 14

def create
  if @user.otp_enabled?
    @signed_user_id = message_verifier.generate(
      @user.id, expires_in: 1.hour
    )
    render template: "admin/sessions/verify_otp"
  else
    authenticate!(@user)
    redirect_to admin_default_url
  end
end

#destroyObject



26
27
28
29
30
# File 'app/controllers/admin/sessions_controller.rb', line 26

def destroy
  flash[:notice] = t("pages_core.logged_out")
  deauthenticate!
  redirect_to 
end

#newObject



10
11
12
# File 'app/controllers/admin/sessions_controller.rb', line 10

def new
  redirect_to admin_default_url if logged_in?
end

#verify_otpObject



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/admin/sessions_controller.rb', line 32

def verify_otp
  @otp_secret = OtpSecret.new(@user)
  if @otp_secret.validate_otp!(params[:otp])
    authenticate!(@user)
    redirect_to admin_default_url
  else
    flash[:notice] = t("pages_core.otp.invalid_code")
    render template: "admin/sessions/verify_otp"
  end
end