Class: DeviseOtp::Devise::OtpTokensController

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.controller_pathObject



85
86
87
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 85

def self.controller_path
  "#{::Devise.otp_controller_path}/otp_tokens"
end

Instance Method Details

#destroyObject

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



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

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



23
24
25
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 23

def edit
  resource.populate_otp_secrets!
end

#recoveryObject



52
53
54
55
56
57
58
59
60
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 52

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



62
63
64
65
66
67
68
69
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 62

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



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

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

#updateObject

Updates the status of OTP authentication



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

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, now: true
    render :edit, status: :unprocessable_entity
  end
end