Skip to content

Commit

Permalink
- hide disable button for mandatory OTP resources;
Browse files Browse the repository at this point in the history
- update disable action to preserve existing OTP token;
- move disable button to bottom of otp_tokens#show page;
  • Loading branch information
strouptl committed Jun 4, 2024
1 parent 879f58e commit b96f33b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/controllers/devise_otp/devise/otp_tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def update
#
def destroy
if resource.disable_otp!
resource.clear_otp_fields!
otp_set_flash_message :success, :successfully_disabled_otp
end

Expand Down
7 changes: 0 additions & 7 deletions app/views/devise/otp_tokens/_token_secret.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
<code><%= resource.otp_auth_secret %></code>
</p>

<p><%= button_to I18n.t('disable_link', :scope => 'devise.otp.otp_tokens'), @resource, :method => :delete, :data => { "turbo-method": "DELETE" } %></p>

<p>
<%= I18n.t('disable_explain', :scope => 'devise.otp.otp_tokens') %>
<strong><%= I18n.t('disable_explain_warn', :scope => 'devise.otp.otp_tokens') %></strong>
</p>

<p><%= button_to I18n.t('reset_link', :scope => 'devise.otp.otp_tokens'), reset_otp_token_path_for(resource), :method => :post , :data => { "turbo-method": "POST" } %></p>

<p>
Expand Down
4 changes: 4 additions & 0 deletions app/views/devise/otp_tokens/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<%- if resource.otp_enabled? %>
<%= render :partial => 'token_secret' if resource.otp_enabled? %>
<%= render :partial => 'trusted_devices' if trusted_devices_enabled? %>

<% unless otp_mandatory_on?(resource) %>
<%= button_to I18n.t('disable_link', :scope => 'devise.otp.otp_tokens'), @resource, :method => :delete, :data => { "turbo-method": "DELETE" } %>
<% end %>
<% else %>
<%= link_to I18n.t('enable_link', :scope => 'devise.otp.otp_tokens'), edit_otp_token_path_for(resource) %>
<% end %>
2 changes: 0 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ en:
title: 'Two-factors Authentication:'
enable_link: 'Enable Two-Factor Authentication'
disable_link: 'Disable Two-Factor Authentication'
disable_explain: 'This will disable Two-Factor authentication and clear the OTP secret.'
disable_explain_warn: 'To re-enable Two-Factor authentication, you will need to enroll your mobile device again.'
reset_link: 'Reset Token Secret'
reset_explain: 'Resetting your token secret will temporarilly disable Two-Factor authentication.'
reset_explain_warn: 'To re-enable Two-Factor authentication, you will need to re-enroll your mobile device with the new token secret.'
Expand Down
2 changes: 2 additions & 0 deletions lib/devise_otp_authenticatable/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class Engine < ::Rails::Engine
ActiveSupport.on_load(:devise_controller) do
include DeviseOtpAuthenticatable::Controllers::UrlHelpers
include DeviseOtpAuthenticatable::Controllers::Helpers
include DeviseOtpAuthenticatable::Controllers::PublicHelpers
end

ActiveSupport.on_load(:action_view) do
include DeviseOtpAuthenticatable::Controllers::UrlHelpers
include DeviseOtpAuthenticatable::Controllers::Helpers
include DeviseOtpAuthenticatable::Controllers::PublicHelpers
end

# See: https://guides.rubyonrails.org/engines.html#separate-assets-and-precompiling
Expand Down

0 comments on commit b96f33b

Please sign in to comment.