Class: CASino::TwoFactorAuthenticatorsController

Inherits:
ApplicationController show all
Includes:
SessionsHelper, TwoFactorAuthenticatorProcessor, TwoFactorAuthenticatorsHelper
Defined in:
app/controllers/casino/two_factor_authenticators_controller.rb

Constant Summary

Constants included from ServiceTicketProcessor

ServiceTicketProcessor::RESERVED_CAS_PARAMETER_KEYS

Instance Method Summary collapse

Methods included from TwoFactorAuthenticatorProcessor

#validate_one_time_password

Methods included from TwoFactorAuthenticatorsHelper

#otp_auth_url, #otp_qr_code_data_url, #otp_qr_code_suggested_size

Methods included from SessionsHelper

#current_ticket_granting_ticket, #current_ticket_granting_ticket?, #current_user, #ensure_signed_in, #set_tgt_cookie, #sign_in, #sign_out, #signed_in?

Methods included from ServiceTicketProcessor

#acquire_service_ticket, #clean_service_url, #service_allowed?, #ticket_valid_for_service?, #validate_ticket_for_service

Methods included from TicketGrantingTicketProcessor

#acquire_ticket_granting_ticket, #cleanup_expired_ticket_granting_tickets, #find_valid_ticket_granting_ticket, #load_or_initialize_user, #remove_ticket_granting_ticket

Methods included from BrowserProcessor

#browser_info, #same_browser?

Methods inherited from ApplicationController

#cookies

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/casino/two_factor_authenticators_controller.rb', line 14

def create
  @two_factor_authenticator = current_user.two_factor_authenticators.where(id: params[:id]).first
  validation_result = validate_one_time_password(params[:otp], @two_factor_authenticator)
  case
  when validation_result.success?
    current_user.two_factor_authenticators.where(active: true).delete_all
    @two_factor_authenticator.update_attribute(:active, true)
    flash[:notice] = I18n.t('two_factor_authenticators.successfully_activated')
    redirect_to sessions_path
  when validation_result.error_code == 'INVALID_OTP'
    flash.now[:error] = I18n.t('two_factor_authenticators.invalid_one_time_password')
    render :new
  else
    flash[:error] = I18n.t('two_factor_authenticators.invalid_two_factor_authenticator')
    redirect_to new_two_factor_authenticator_path
  end
end

#destroyObject



32
33
34
35
36
37
38
39
# File 'app/controllers/casino/two_factor_authenticators_controller.rb', line 32

def destroy
  authenticators = current_user.two_factor_authenticators.where(id: params[:id])
  if authenticators.any?
    authenticators.first.destroy
    flash[:notice] = I18n.t('two_factor_authenticators.successfully_deleted')
  end
  redirect_to sessions_path
end

#newObject



10
11
12
# File 'app/controllers/casino/two_factor_authenticators_controller.rb', line 10

def new
  @two_factor_authenticator = current_user.two_factor_authenticators.create! secret: ROTP::Base32.random_base32
end