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



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

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

  redirect_to action: :show
end

#delete_persistenceObject

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



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

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

  redirect_to action: :show
end

#destroyObject

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



37
38
39
40
41
42
43
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 37

def destroy
  if resource.reset_otp_credentials!
    otp_set_flash_message :success, :successfully_reset_creds
  end

  redirect_to action: :show
end

#get_persistenceObject

makes the current browser persistent



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

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

  redirect_to action: :show
end

#recoveryObject



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

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

#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



25
26
27
28
29
30
31
32
# File 'app/controllers/devise_otp/devise/otp_tokens_controller.rb', line 25

def update
  enabled = params[resource_name][:otp_enabled] == "1"
  if enabled ? resource.enable_otp! : resource.disable_otp!
    otp_set_flash_message :success, :successfully_updated
  end

  render :show
end