Sha256: 9a21202bc8d8dfd11c958b3ca5f3a91cab63b0dc357534ac07a039f27068066d

Contents?: true

Size: 780 Bytes

Versions: 24

Compression:

Stored size: 780 Bytes

Contents

class TwoFactorAuthentication::Profile::RecoveryCodesController < ApplicationController
  before_action :set_user

  def index
    if Current.user.recovery_codes.exists?
      @recovery_codes = @user.recovery_codes
    else
      @recovery_codes = @user.recovery_codes.create!(new_recovery_codes)
    end
  end

  def create
    @user.recovery_codes.delete_all
    @user.recovery_codes.create!(new_recovery_codes)

    redirect_to two_factor_authentication_profile_recovery_codes_path, notice: "Your new recovery codes have been generated"
  end

  private
    def set_user
      @user = Current.user
    end

    def new_recovery_codes
      10.times.map { { code: new_recovery_code } }
    end

    def new_recovery_code
      SecureRandom.alphanumeric(10).downcase
    end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
authentication-zero-2.16.24 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.23 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.22 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.21 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt