Sha256: 6d84e9cefa7d7b9f8d1416f89247d99581582ece68a7f44344b58efb5aa4d9b6

Contents?: true

Size: 707 Bytes

Versions: 5

Compression:

Stored size: 707 Bytes

Contents

class TwoFactorAuthentication::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_recovery_codes_path
    else
      redirect_to new_two_factor_authentication_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

5 entries across 5 versions & 1 rubygems

Version Path
authentication-zero-2.16.20 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.19 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.18 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.17 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.16 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt