Class: QuoVadis::TotpsController

Inherits:
QuoVadisController show all
Defined in:
app/controllers/quo_vadis/totps_controller.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/quo_vadis/totps_controller.rb', line 41

def authenticate
  @totp = authenticated_model..totp
  if @totp.verify params[:totp]
    qv.log authenticated_model., Log::TOTP_SUCCESS
    qv.replace_session
    qv.session_authenticated_with_second_factor
    redirect_to qv.path_after_authentication, notice: QuoVadis.translate('flash.login.success')
  else
    if @totp.reused? params[:totp]
      qv.log authenticated_model., Log::TOTP_REUSE
      QuoVadis.notify :totp_reuse_notification, email: authenticated_model.email
    else
      qv.log authenticated_model., Log::TOTP_FAILURE
    end
    flash.now[:alert] = QuoVadis.translate('flash.totp.unverified')
    render :challenge, status: :unprocessable_entity
  end
end

#challengeObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/quo_vadis/totps_controller.rb', line 30

def challenge
   = authenticated_model.

  unless .has_two_factors?
    redirect_to new_totp_path, alert: QuoVadis.translate('flash.totp.setup') and return
  end

  @totp = .totp
end

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/quo_vadis/totps_controller.rb', line 13

def create
  @totp = authenticated_model..build_totp(
    key:               totp_params[:key],
    provided_hmac_key: totp_params[:hmac_key]
  )
  if @totp.verify params[:totp][:otp]
    qv.log authenticated_model., Log::TOTP_SETUP
    QuoVadis.notify :totp_setup_notification, email: authenticated_model.email
    qv.session_authenticated_with_second_factor
    flash[:recovery_codes] = generate_recovery_codes
    redirect_to recovery_codes_path
  else
    redirect_to new_totp_path, alert: QuoVadis.translate('flash.totp.unverified')
  end
end

#newObject



8
9
10
# File 'app/controllers/quo_vadis/totps_controller.rb', line 8

def new
  @totp = authenticated_model..build_totp
end