Sha256: 39d4d9be60f399c2a287aac30befb19f137dcb4d919318f2f3d6e52c61edf9f9

Contents?: true

Size: 1000 Bytes

Versions: 3

Compression:

Stored size: 1000 Bytes

Contents

class TwoFactorAuthentication::TotpsController < ApplicationController
  before_action :set_<%= singular_table_name %>
  before_action :set_totp

  def new
    @qr_code = RQRCode::QRCode.new(@totp.provisioning_uri(@<%= singular_table_name %>.email))
  end

  def create
    if !@<%= singular_table_name %>.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)
      @<%= singular_table_name %>.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_<%= singular_table_name %>
    @<%= singular_table_name %> = Current.<%= singular_table_name %>
  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.11.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.11.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.11.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt