once-campfire icon indicating copy to clipboard operation
once-campfire copied to clipboard

[Feature - Reset Password Flow]

Open milos-dukic opened this issue 2 months ago • 3 comments

PR for issue #72 Files changed:

  • app/assets/stylesheets/messages.css - some UI styling for error message
  • app/controllers/sessions/password_resets_controller.rb - new controller for handling the reset password flow
  • app/helpers/application_helper.rb - new helper method for checking is smtp is configured
  • app/javascript/controllers/password_reset_controller.js - new Stimulus controller for checking the new password and for displaying errors
  • app/mailers/application_mailer.rb - new application mailer
  • app/mailers/password_reset_mailer.rb - password reset mailer
  • app/models/user.rb - updated User model to be resettable
  • app/models/user/resettable.rb - new concern for password reset
  • app/views/password_reset_mailer/password_reset_email.html.erb - password reset HTML view
  • app/views/password_reset_mailer/password_reset_email.text.erb - password reset text view
  • app/views/sessions/new.html.erb - Added button for forgot password
  • app/views/sessions/password_resets/index.html.erb - HTML to input user email
  • app/views/sessions/password_resets/new.html.erb - HTML that email with reset link has been sent
  • app/views/sessions/password_resets/show.html.erb - HTML to enter new passwrod
  • config/environments/development.rb - SMTP development setup
  • config/environments/production.rb - SMPT production setup
  • config/routes.rb - new routes for password reset flow
  • test/mailers/fixture_templates/password_reset_html_fixture.txt - new fixture for html reset email
  • test/mailers/fixture_templates/password_reset_text_fixture.txt - new fixture for text reset email
  • test/mailers/password_reset_mailer_test.rb - new test
  • test/mailers/previews/password_reset_mailer_preview.rb - new test
  • config/environments/* - updated with new ENVs

ENV setup:

  • SMTP_ENABLED - defaults to false
  • SMTP_ADDRESS - obtained from mailing service
  • SMTP_PORT - obtained from mailing service
  • SMTP_DOMAIN - obtained from mailing service
  • SMTP_USER_NAME - obtained from mailing service
  • SMTP_PASSWORD - obtained from mailing service
  • SMTP_INFO_EMAIL_FROM - defaults to [email protected]
  • SMTP_PASSWORD_RESET_EMAIL_FROM - defaults to [email protected]

For SMTP feature to be enable i.e. supported following ENVs MUST be set:

  • SMTP_ENABLED
  • SMTP_ADDRESS
  • SMTP_PORT
  • SMTP_DOMAIN
  • SMTP_USER_NAME
  • SMTP_PASSWORD

SMTP config development:

  config.feature_enable_smtp = ENV.fetch("SMTP_ENABLED", false)
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:         ENV["SMTP_ADDRESS"],
    port:            ENV["SMTP_PORT"],
    domain:          ENV["SMTP_DOMAIN"],
    user_name:       ENV["SMTP_USER_NAME"],
    password:        ENV["SMTP_PASSWORD"],
    authentication:  "plain",
    open_timeout:    5,
    read_timeout:    5,
    openssl_verify_mode:  "none"
  }

Note openssl_verify_mode: "none" is set since I had issues with certificates in sandbox env.

SMTP config production:

  config.feature_enable_smtp = ENV.fetch("SMTP_ENABLED", false)
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:         ENV["SMTP_ADDRESS"],
    port:            ENV["SMTP_PORT"],
    domain:          ENV["SMTP_DOMAIN"],
    user_name:       ENV["SMTP_USER_NAME"],
    password:        ENV["SMTP_PASSWORD"],
    authentication:  "plain",
    enable_starttls: true,
    open_timeout:    5,
    read_timeout:    5
  }

Screenshots: 1

2 3 4 5

milos-dukic avatar Oct 23 '25 08:10 milos-dukic

@p-schlickmann updated the PR :) thx for the review btw

milos-dukic avatar Oct 24 '25 14:10 milos-dukic

@p-schlickmann updated PR :) with one comment on test/mailers/password_reset_mailer_test.rb thx

milos-dukic avatar Oct 27 '25 14:10 milos-dukic

Thanks @milos-dukic, I'll wait for a mantainer's opinion now.

p-schlickmann avatar Oct 28 '25 19:10 p-schlickmann