lib/rodauth/features/reset_password.rb in rodauth-1.9.0 vs lib/rodauth/features/reset_password.rb in rodauth-1.10.0

- old
+ new

@@ -1,17 +1,18 @@ # frozen-string-literal: true module Rodauth - ResetPassword = Feature.define(:reset_password) do + Feature.define(:reset_password, :ResetPassword) do depends :login, :email_base, :login_password_requirements_base notice_flash "Your password has been reset" notice_flash "An email has been sent to you with a link to reset the password for your account", 'reset_password_email_sent' error_flash "There was an error resetting your password" error_flash "There was an error requesting a password reset", 'reset_password_request' - loaded_templates %w'reset-password password-field password-confirm-field reset-password-email' + loaded_templates %w'reset-password-request reset-password password-field password-confirm-field reset-password-email' view 'reset-password', 'Reset Password' + view 'reset-password-request', 'Request Password Reset', 'reset_password_request' additional_form_tags additional_form_tags 'reset_password_request' before before 'reset_password_request' after @@ -30,16 +31,17 @@ auth_value_method :reset_password_table, :account_password_reset_keys auth_value_method :reset_password_id_column, :id auth_value_method :reset_password_key_column, :key auth_value_method :reset_password_session_key, :reset_password_key - auth_value_methods :reset_password_email_sent_redirect + auth_value_methods :reset_password_email_sent_redirect, :reset_password_request_link auth_methods( :create_reset_password_key, :create_reset_password_email, :get_reset_password_key, + :login_failed_reset_password_request_form, :remove_reset_password_key, :reset_password_email_body, :reset_password_email_link, :reset_password_key_insert_hash, :reset_password_key_value, @@ -51,10 +53,14 @@ route(:reset_password_request) do |r| check_already_logged_in before_reset_password_request_route + r.get do + reset_password_request_view + end + r.post do if account_from_login(param(login_param)) && open_account? generate_reset_password_key_value transaction do before_reset_password_request @@ -171,17 +177,25 @@ def get_password_reset_key(id) password_reset_ds(id).get(reset_password_key_column) end + def login_form_footer + super + reset_password_request_link + end + + def reset_password_request_link + "<p><a href=\"#{prefix}/#{reset_password_request_route}\">Forgot Password?</a></p>" + end + private attr_reader :reset_password_key_value def after_login_failure unless only_json? - @login_form_header = render("reset-password-request") + @login_form_header = login_failed_reset_password_request_form end super end def after_close_account @@ -193,9 +207,13 @@ @reset_password_key_value = random_key end def create_reset_password_email create_email(reset_password_email_subject, reset_password_email_body) + end + + def login_failed_reset_password_request_form + render("reset-password-request") end def reset_password_email_body render('reset-password-email') end