Skip to content

Commit a13d39a

Browse files
committed
Make verify-account-resend page work if verify_account_resend_explanatory_text calls verify_account_email_recently_sent?
This can happen in Rodauth configurations that want to suppress the notice if the account has not sent the email recently. This makes verify_account_email_recently_sent? return falsely if there is no associated account, such as when the page is visited directly, instead of being displayed in response to an account creation or login attempt. Note that if there is no account, the warning should be displayed, because at that point you do not know whether the email was sent recently or not.
1 parent 714c082 commit a13d39a

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
=== master
22

3+
* Make verify-account-resend page work if verify_account_resend_explanatory_text calls verify_account_email_recently_sent? (jeremyevans)
4+
35
* Specify fixed locals for rendered templates by default, disable with use_template_fixed_locals? false (jeremyevans)
46

57
* Make rodauth.has_password? method public (enescakir) (#461)

lib/rodauth/features/verify_account.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def setup_account_verification
241241
end
242242

243243
def verify_account_email_recently_sent?
244-
(email_last_sent = get_verify_account_email_last_sent) && (Time.now - email_last_sent < verify_account_skip_resend_email_within)
244+
account && (email_last_sent = get_verify_account_email_last_sent) && (Time.now - email_last_sent < verify_account_skip_resend_email_within)
245245
end
246246

247247
private

spec/verify_account_spec.rb

+32
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,38 @@ def bcrypt_password.==(other)
318318
page.find('#notice_flash').text.must_equal "Your account has been verified"
319319
end
320320

321+
it "should support accessing verify-account-resend route when not logged in and verify_account_resend_explanatory_text calls verify_account_email_recently_sent?" do
322+
rodauth do
323+
enable :login, :verify_account
324+
verify_account_skip_resend_email_within(-1)
325+
verify_account_resend_explanatory_text{super() if verify_account_email_recently_sent?}
326+
end
327+
roda do |r|
328+
r.rodauth
329+
r.root{view :content=>"Home"}
330+
end
331+
332+
visit '/create-account'
333+
fill_in 'Login', :with=>'[email protected]'
334+
click_button 'Create Account'
335+
page.find('#notice_flash').text.must_equal "An email has been sent to you with a link to verify your account"
336+
page.current_path.must_equal '/'
337+
Mail::TestMailer.deliveries.size.must_equal 1
338+
339+
visit '/verify-account-resend'
340+
page.title.must_equal 'Resend Verification Email'
341+
fill_in 'Login', :with=>'[email protected]'
342+
click_button 'Send Verification Email Again'
343+
Mail::TestMailer.deliveries.size.must_equal 2
344+
345+
346+
page.html.wont_include "Login"
347+
page.title.must_equal 'Resend Verification Email'
348+
click_button 'Send Verification Email Again'
349+
Mail::TestMailer.deliveries.size.must_equal 3
350+
Mail::TestMailer.deliveries.clear
351+
end
352+
321353
it "should not display verify account resend link on login page when route is disabled" do
322354
route = "verify-account-resend"
323355
rodauth do

0 commit comments

Comments
 (0)