diff --git a/app/controllers/devise/two_factor_authentication_controller.rb b/app/controllers/devise/two_factor_authentication_controller.rb index f40c10c..3e3d541 100644 --- a/app/controllers/devise/two_factor_authentication_controller.rb +++ b/app/controllers/devise/two_factor_authentication_controller.rb @@ -15,6 +15,11 @@ class Devise::TwoFactorAuthenticationController < DeviseController end end + def resend_code + resource.send_two_factor_authentication_code + redirect_to user_two_factor_authentication_path, notice: "Your authentication code has been sent." + end + private def after_two_factor_success_for(resource) diff --git a/app/views/devise/two_factor_authentication/show.html.erb b/app/views/devise/two_factor_authentication/show.html.erb index 32ce38b..1761ec1 100644 --- a/app/views/devise/two_factor_authentication/show.html.erb +++ b/app/views/devise/two_factor_authentication/show.html.erb @@ -7,4 +7,5 @@ <%= submit_tag "Submit" %> <% end %> -<%= link_to "Sign out", destroy_user_session_path, :method => :delete %> +<%= link_to 'Resend Code', resend_code_user_two_factor_authentication_path, action: :get %> +<%= link_to "Sign out", destroy_user_session_path, :method => :delete %> \ No newline at end of file diff --git a/lib/two_factor_authentication/routes.rb b/lib/two_factor_authentication/routes.rb index 942c9d1..543059a 100644 --- a/lib/two_factor_authentication/routes.rb +++ b/lib/two_factor_authentication/routes.rb @@ -3,7 +3,9 @@ module ActionDispatch::Routing protected def devise_two_factor_authentication(mapping, controllers) - resource :two_factor_authentication, :only => [:show, :update], :path => mapping.path_names[:two_factor_authentication], :controller => controllers[:two_factor_authentication] + resource :two_factor_authentication, :only => [:show, :update, :resend_code], :path => mapping.path_names[:two_factor_authentication], :controller => controllers[:two_factor_authentication] do + collection { get "resend_code" } + end end end end