Sha256: 13c6ba02843d4d10e536b199c9c2bcb263032d6c3fc9da2c0c6d765e48c89ed5
Contents?: true
Size: 1.02 KB
Versions: 10
Compression:
Stored size: 1.02 KB
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 <%- unless options.sudoable? -%> 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) <%- else -%> if @totp.verify(params[:code], drift_behind: 15) <%- end -%> @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
10 entries across 10 versions & 1 rubygems