Class: DeviseOtp::Devise::OtpTokensController

Inherits:
DeviseController
  • Object
show all
Includes:
Devise::Controllers::Helpers
Defined in:
app/controllers/devise_otp/devise/otp_tokens_controller.rb

Instance Method Summary collapse

Instance Method Details

#clear_persistenceObject

clears persistence for the current browser



68
69
70
71
72
73
74
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 68

def clear_persistence
  if otp_clear_trusted_device_for(resource)
    otp_set_flash_message :success, :successfully_cleared_persistence
  end

  redirect_to otp_token_path_for(resource)
end

#delete_persistenceObject

rehash the persistence secret, thus, making all the persistence cookies invalid



79
80
81
82
83
84
85
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 79

def delete_persistence
  if otp_reset_persistence_for(resource)
    otp_set_flash_message :notice, :successfully_reset_persistence
  end

  redirect_to otp_token_path_for(resource)
end

#destroyObject

Resets OTP authentication, generates new credentials, sets it to off



46
47
48
49
50
51
52
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 46

def destroy
  if resource.disable_otp!
    otp_set_flash_message :success, :successfully_disabled_otp
  end

  redirect_to otp_token_path_for(resource)
end

#editObject

Displays the QR Code and Validation Token form for enabling the OTP



25
26
27
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 25

def edit
  resource.populate_otp_secrets!
end

#get_persistenceObject

makes the current browser persistent



57
58
59
60
61
62
63
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 57

def get_persistence
  if otp_set_trusted_device_for(resource)
    otp_set_flash_message :success, :successfully_set_persistence
  end

  redirect_to otp_token_path_for(resource)
end

#recoveryObject



87
88
89
90
91
92
93
94
95
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 87

def recovery
  respond_to do |format|
    format.html
    format.js
    format.text do
      send_data render_to_string(template: "#{controller_path}/recovery_codes"), filename: "otp-recovery-codes.txt", format: "text"
    end
  end
end

#resetObject



97
98
99
100
101
102
103
104
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 97

def reset
  if resource.disable_otp!
    resource.clear_otp_fields!
    otp_set_flash_message :success, :successfully_reset_otp
  end

  redirect_to edit_otp_token_path_for(resource)
end

#showObject

Displays the status of OTP authentication



14
15
16
17
18
19
20
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 14

def show
  if resource.nil?
    redirect_to stored_location_for(scope) || :root
  else
    render :show
  end
end

#updateObject

Updates the status of OTP authentication



32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 32

def update
  if resource.valid_otp_token?(params[:confirmation_code])
    resource.enable_otp!
    otp_set_flash_message :success, :successfully_updated
    redirect_to otp_token_path_for(resource)
  else
    otp_set_flash_message :danger, :could_not_confirm
    render :edit
  end
end