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-4.0.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-4.0.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-4.0.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-4.0.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-3.0.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-3.0.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-3.0.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.36 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.35 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.34 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.33 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.32 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.31 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.30 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.29 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/recovery_codes_controller.rb.tt