From 5bd816adf6252dca28465d5030e2484e04ed6120 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 17 Dec 2024 13:16:19 -0800 Subject: [PATCH] Make rodauth.*_email_recently_sent? methods public This affects the following methods: * email_auth_email_recently_sent? * unlock_account_email_recently_sent? * reset_password_email_recently_sent? * verify_account_email_recently_sent? This provides a supported method for the user to check whether the related emails have been recently sent. --- CHANGELOG | 2 ++ lib/rodauth/features/email_auth.rb | 8 ++++---- lib/rodauth/features/lockout.rb | 8 ++++---- lib/rodauth/features/reset_password.rb | 8 ++++---- lib/rodauth/features/verify_account.rb | 8 ++++---- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f4444784..21b50ef2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ === master +* Make rodauth.*_email_recently_sent? methods public (jeremyevans) + * Add Rodauth::ConfigurationError, and use it for configuration errors (janko) (#458) === 2.37.0 (2024-11-19) diff --git a/lib/rodauth/features/email_auth.rb b/lib/rodauth/features/email_auth.rb index 46b5f518..ae6a3c6c 100644 --- a/lib/rodauth/features/email_auth.rb +++ b/lib/rodauth/features/email_auth.rb @@ -163,6 +163,10 @@ def possible_authentication_methods methods end + def email_auth_email_recently_sent? + (email_last_sent = get_email_auth_email_last_sent) && (Time.now - email_last_sent < email_auth_skip_resend_email_within) + end + private def _multi_phase_login_forms @@ -171,10 +175,6 @@ def _multi_phase_login_forms forms end - def email_auth_email_recently_sent? - (email_last_sent = get_email_auth_email_last_sent) && (Time.now - email_last_sent < email_auth_skip_resend_email_within) - end - def _email_auth_request if email_auth_email_recently_sent? set_redirect_error_flash email_auth_email_recently_sent_error_flash diff --git a/lib/rodauth/features/lockout.rb b/lib/rodauth/features/lockout.rb index 9c89dc10..b0eaa165 100644 --- a/lib/rodauth/features/lockout.rb +++ b/lib/rodauth/features/lockout.rb @@ -237,6 +237,10 @@ def set_unlock_account_email_last_sent account_lockouts_ds.update(account_lockouts_email_last_sent_column=>Sequel::CURRENT_TIMESTAMP) if account_lockouts_email_last_sent_column end + def unlock_account_email_recently_sent? + (email_last_sent = get_unlock_account_email_last_sent) && (Time.now - email_last_sent < unlock_account_skip_resend_email_within) + end + private attr_reader :unlock_account_key_value @@ -278,10 +282,6 @@ def show_lockout_page return_response unlock_account_request_view end - def unlock_account_email_recently_sent? - (email_last_sent = get_unlock_account_email_last_sent) && (Time.now - email_last_sent < unlock_account_skip_resend_email_within) - end - def use_date_arithmetic? super || db.database_type == :mysql end diff --git a/lib/rodauth/features/reset_password.rb b/lib/rodauth/features/reset_password.rb index cabea529..a17558ea 100644 --- a/lib/rodauth/features/reset_password.rb +++ b/lib/rodauth/features/reset_password.rb @@ -204,16 +204,16 @@ def get_reset_password_email_last_sent end end + def reset_password_email_recently_sent? + (email_last_sent = get_reset_password_email_last_sent) && (Time.now - email_last_sent < reset_password_skip_resend_email_within) + end + private def _login_form_footer_links super << [20, reset_password_request_path, reset_password_request_link_text] end - def reset_password_email_recently_sent? - (email_last_sent = get_reset_password_email_last_sent) && (Time.now - email_last_sent < reset_password_skip_resend_email_within) - end - attr_reader :reset_password_key_value def after_login_failure diff --git a/lib/rodauth/features/verify_account.rb b/lib/rodauth/features/verify_account.rb index a27b857a..ec467a21 100644 --- a/lib/rodauth/features/verify_account.rb +++ b/lib/rodauth/features/verify_account.rb @@ -240,6 +240,10 @@ def setup_account_verification send_verify_account_email end + def verify_account_email_recently_sent? + (email_last_sent = get_verify_account_email_last_sent) && (Time.now - email_last_sent < verify_account_skip_resend_email_within) + end + private def _login_form_footer_links @@ -250,10 +254,6 @@ def _login_form_footer_links links end - def verify_account_email_recently_sent? - (email_last_sent = get_verify_account_email_last_sent) && (Time.now - email_last_sent < verify_account_skip_resend_email_within) - end - attr_reader :verify_account_key_value def before_login_attempt