Sha256: f1e37ae2fb5a76bcdb3f3e958510b47751d9b3c6778e0c301db96dddbbe5f7a3

Contents?: true

Size: 691 Bytes

Versions: 5

Compression:

Stored size: 691 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 root_path, notice: "2FA is enabled on your account"
    else
      redirect_to new_two_factor_authentication_totp_path, alert: "That code didn't work. Please try again"
    end
  end

  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.15 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.14 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.13 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.12 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.11 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt