Sha256: c5ef15bef9d311b0b98c8f86b27266d1619e9af2a46762d87bb06294d9f4ac23

Contents?: true

Size: 883 Bytes

Versions: 35

Compression:

Stored size: 883 Bytes

Contents

class TwoFactorAuthentication::ChallengesController < 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)
      session = @user.sessions.create!
      cookies.signed.permanent[:session_token] = { value: session.id, httponly: true }

      redirect_to root_path, notice: "Signed in successfully"
    else
      redirect_to new_two_factor_authentication_challenge_path(token: params[:token]), alert: "That code didn't work. Please try again"
    end
  end

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

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
authentication-zero-2.15.5 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.15.4 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.15.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.15.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.15.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.15.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.14.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.13.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.6 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.5 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.4 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.3 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.2 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.1 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt
authentication-zero-2.12.0 lib/generators/authentication/templates/controllers/html/two_factor_authentication/challenges_controller.rb.tt