Class: Devise::TokensController

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

Instance Method Summary collapse

Instance Method Details

#clear_persistenceObject

clears persistence for the current browser



54
55
56
57
58
59
60
# File 'app/controllers/devise/tokens_controller.rb', line 54

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



65
66
67
68
69
70
71
# File 'app/controllers/devise/tokens_controller.rb', line 65

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



34
35
36
37
38
39
# File 'app/controllers/devise/tokens_controller.rb', line 34

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

#get_persistenceObject

makes the current browser persistent



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

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



76
77
78
79
80
81
82
83
84
# File 'app/controllers/devise/tokens_controller.rb', line 76

def recovery
  respond_to do |format|
    format.html
    format.js
    format.text do
      send_data render_to_string(template: 'devise/tokens/recovery_codes.text.erb'), filename: 'recovery-codes.txt'
    end
  end
end

#showObject

Displays the status of OTP authentication



12
13
14
15
16
17
18
# File 'app/controllers/devise/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



23
24
25
26
27
28
29
# File 'app/controllers/devise/tokens_controller.rb', line 23

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