Class: Kiqr::Users::Settings::TwoFactorController
- Inherits:
-
BaseController
- Object
- BaseController
- Kiqr::Users::Settings::TwoFactorController
- Defined in:
- app/controllers/kiqr/users/settings/two_factor_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/kiqr/users/settings/two_factor_controller.rb', line 18 def create if @user.validate_and_consume_otp!(params[:user][:otp_attempt]) @user.update(otp_required_for_login: true) :success, :two_factor_enabled redirect_to user_settings_two_factor_path else @user.errors.add(:otp_attempt, I18n.t("kiqr.users.settings.two_factor.form.invalid_otp")) render turbo_stream: turbo_stream.replace("two_factor_form", partial: "kiqr/users/settings/two_factor/form", locals: { user: @user }), status: :unprocessable_content end end |
#destroy ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/kiqr/users/settings/two_factor_controller.rb', line 29 def destroy return redirect_to user_settings_two_factor_path unless two_factor_enabled? if @user.validate_and_consume_otp!(params.dig(:user, :otp_attempt)) @user.update(otp_required_for_login: false, otp_backup_codes: []) :success, :two_factor_disabled redirect_to user_settings_two_factor_path else @user.errors.add(:otp_attempt, I18n.t("kiqr.users.settings.two_factor.form.invalid_otp")) render :show, status: :unprocessable_content end end |
#new ⇒ Object
9 10 11 12 13 14 |
# File 'app/controllers/kiqr/users/settings/two_factor_controller.rb', line 9 def new # Reset the OTP secret to make sure that the user has a fresh secret key. # This will also reset the otp_required_for_login flag to make sure the user # doesn't get locked out of their account. @user.reset_otp_secret! end |
#show ⇒ Object
16 |
# File 'app/controllers/kiqr/users/settings/two_factor_controller.rb', line 16 def show; end |