From 14adcce36236662763e5427d188323c6263d4a8f Mon Sep 17 00:00:00 2001 From: JD Trout Date: Tue, 11 Aug 2015 10:49:26 -0700 Subject: [PATCH] Add ability to resend code --- .../devise/two_factor_authentication_controller.rb | 5 +++++ app/views/devise/two_factor_authentication/show.html.erb | 3 ++- lib/two_factor_authentication/routes.rb | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/devise/two_factor_authentication_controller.rb b/app/controllers/devise/two_factor_authentication_controller.rb index e302e01..97c3ee0 100644 --- a/app/controllers/devise/two_factor_authentication_controller.rb +++ b/app/controllers/devise/two_factor_authentication_controller.rb @@ -27,6 +27,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 authenticate_scope! 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