Sha256: 8567233cbc291f1bce899133bf5a7d64c137f2a1c53a99a1a374747abfcc428f

Contents?: true

Size: 846 Bytes

Versions: 4

Compression:

Stored size: 846 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 !@user.authenticate(params[:current_password])
      redirect_to two_factor_authentication_totp_path, alert: "The password you entered is incorrect"
    elsif @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 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

4 entries across 4 versions & 1 rubygems

Version Path
authentication-zero-2.16.9 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.8 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.7 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.6 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt