Class: TwoFactorAuthenticationsController

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

Instance Method Summary collapse

Instance Method Details

#confirm_2faObject


17
18
19
# File 'app/controllers/two_factor_authentications_controller.rb', line 17

def confirm_2fa
  redirect_to two_factor_authentication_path if current_user.otp_required_for_login?
end

#confirm_and_activate_2faObject


21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/two_factor_authentications_controller.rb', line 21

def confirm_and_activate_2fa
  if current_user.validate_and_consume_otp!(params[:user][:code])
    current_user. = true
    current_user.save!

    flash[:notice] = t("two_factor_auth.flash.success_activation")
    redirect_to recovery_codes_two_factor_authentication_path
  else
    flash[:alert] = t("two_factor_auth.flash.error_token")
    redirect_to confirm_two_factor_authentication_path
  end
end

#createObject


11
12
13
14
15
# File 'app/controllers/two_factor_authentications_controller.rb', line 11

def create
  current_user.otp_secret = User.generate_otp_secret(32)
  current_user.save!
  redirect_to confirm_two_factor_authentication_path
end

#destroyObject


39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/two_factor_authentications_controller.rb', line 39

def destroy
  if current_user.valid_password?(params[:two_factor_authentication][:password])
    current_user. = false
    current_user.save!
    flash[:notice] = t("two_factor_auth.flash.success_deactivation")
  else
    flash[:alert] = t("users.destroy.wrong_password")
  end
  redirect_to two_factor_authentication_path
end

#recovery_codesObject


34
35
36
37
# File 'app/controllers/two_factor_authentications_controller.rb', line 34

def recovery_codes
  @recovery_codes = current_user.generate_otp_backup_codes!
  current_user.save!
end

#showObject


7
8
9
# File 'app/controllers/two_factor_authentications_controller.rb', line 7

def show
  @user = current_user
end