Sha256: c59fa6a66d17ca4cd4958cd527f24d1a6880b69177224bfea0a25dfe228db218

Contents?: true

Size: 732 Bytes

Versions: 3

Compression:

Stored size: 732 Bytes

Contents

class TwoFactorAuthentication::Profile::TotpsController < ApplicationController
  before_action :set_user
  before_action :set_totp

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

  def create
    if @totp.verify(params[:code], drift_behind: 15)
      @user.update! otp_secret: params[:secret]
      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

  private
    def set_user
      @user = Current.user
    end

    def set_totp
      @totp = ROTP::TOTP.new(params[:secret] || ROTP::Base32.random, issuer: "YourAppName")
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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