Sha256: bb614da202708361b82180372da979e0782f4e0c3eae8dbda1a62b9ac677f96e

Contents?: true

Size: 927 Bytes

Versions: 20

Compression:

Stored size: 927 Bytes

Contents

class TwoFactorAuthentication::Profile::TotpsController < ApplicationController
  before_action :set_user
  before_action :set_totp, only: %i[ new create ]

  def new
    @qr_code = RQRCode::QRCode.new(provisioning_uri)
  end

  def create
    if @totp.verify(params[:code], drift_behind: 15)
      @user.update! otp_required_for_sign_in: true
      redirect_to two_factor_authentication_profile_recovery_codes_path
    else
      redirect_to new_two_factor_authentication_profile_totp_path, alert: "That code didn't work. Please try again"
    end
  end

  def update
    @user.update! otp_secret: ROTP::Base32.random
    redirect_to new_two_factor_authentication_profile_totp_path
  end

  private
    def set_user
      @user = Current.user
    end

    def set_totp
      @totp = ROTP::TOTP.new(@user.otp_secret, issuer: "YourAppName")
    end

    def provisioning_uri
      @totp.provisioning_uri @user.email
    end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
authentication-zero-4.0.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-4.0.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-4.0.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-4.0.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-3.0.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-3.0.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-3.0.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.36 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.35 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.34 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.33 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.32 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.31 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.30 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.29 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/html/two_factor_authentication/profile/totps_controller.rb.tt