Sha256: a706994097bbdc88c7208070ebfee35923504550d607afe3edf7424599144986

Contents?: true

Size: 762 Bytes

Versions: 15

Compression:

Stored size: 762 Bytes

Contents

class TwoFactorAuthentication::TotpsController < ApplicationController
  <%- if options.sudoable? -%>
  before_action :require_sudo
  <%- end -%>
  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 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

15 entries across 15 versions & 1 rubygems

Version Path
authentication-zero-2.16.5 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.4 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.16.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.9 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.8 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.7 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.6 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.5 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt
authentication-zero-2.15.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/totps_controller.rb.tt