Class: Admin::SecurityController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/security_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#cache, #pagination_parameters, #trusty_config

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #initialize, #template_name

Methods included from LoginSystem

included

Constructor Details

This class inherits a constructor from ApplicationController

Instance Method Details

#disable_two_factorObject



39
40
41
42
43
44
45
46
# File 'app/controllers/admin/security_controller.rb', line 39

def disable_two_factor
  if @user.update(otp_required_for_login: false, otp_secret: nil)
    redirect_to admin_security_path, notice: t('security_controller.two_factor_disabled')
  else
    flash[:error] = t('security_controller.two_factor_disabled_error')
    redirect_to admin_security_path
  end
end

#editObject



15
16
17
# File 'app/controllers/admin/security_controller.rb', line 15

def edit
  render
end

#showObject



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

def show
  set_standard_body_style
  render :edit
end

#updateObject



19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin/security_controller.rb', line 19

def update
  if @user.update(security_params)
    sign_out(@user)
    redirect_to new_user_session_path, notice: t('security_controller.password_updated')
  else
    flash[:error] = t('security_controller.error_updating_password')
    render :edit
  end
end

#verify_two_factorObject



29
30
31
32
33
34
35
36
37
# File 'app/controllers/admin/security_controller.rb', line 29

def verify_two_factor
  if @user.validate_and_consume_otp!(params[:otp_attempt])
    @user.update!(otp_required_for_login: true)
    redirect_to admin_security_path, notice: t('security_controller.two_factor_enabled')
  else
    flash[:error] = t('security_controller.two_factor_invalid_code')
    redirect_to admin_security_path
  end
end