Sha256: 571a2ef63bf2f5a322f7086d5b1c02b2908d9f47cd8d773b9d328f1dd4c9e136

Contents?: true

Size: 977 Bytes

Versions: 8

Compression:

Stored size: 977 Bytes

Contents

class TwoFactorAuthentication::Challenge::TotpsController < ApplicationController
  skip_before_action :authenticate

  before_action :set_user

  def new
  end

  def create
    @totp = ROTP::TOTP.new(@user.otp_secret, issuer: "YourAppName")

    if @totp.verify(params[:code], drift_behind: 15)
      sign_in_and_redirect_to_root
    else
      redirect_to new_two_factor_authentication_challenge_totp_path, alert: "That code didn't work. Please try again"
    end
  end

  private
    def set_user
      @user = User.find_signed!(session[:challenge_token], purpose: :authentication_challenge)
    rescue StandardError
      redirect_to sign_in_path, alert: "That's taking too long. Please re-enter your password and try again"
    end

    def sign_in_and_redirect_to_root
      session = @user.sessions.create!
      cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }

      redirect_to root_path, notice: "Signed in successfully"
    end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.24 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.23 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.22 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt
authentication-zero-2.16.21 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenge/totps_controller.rb.tt