GRN-45: Fixed the URL being sent in the password reset email (#351)

* Fixed the url used in the reset password emails and added the ability to preview emails in the dev environment

* Replaced localhost with example.com in email previews

* Update password_reset.html.erb
v2
farhatahmad 4 years ago committed by Jesus Federico
parent ecee282fc4
commit c73064a70a
  1. 6
      app/controllers/password_resets_controller.rb
  2. 2
      app/views/user_mailer/password_reset.html.erb
  3. 2
      app/views/user_mailer/password_reset.text.erb
  4. 16
      test/mailers/previews/user_mailer_preview.rb

@ -29,7 +29,7 @@ class PasswordResetsController < ApplicationController
@user = User.find_by(email: params[:password_reset][:email].downcase)
if @user
@user.create_reset_digest
@user.send_password_reset_email(request.base_url)
@user.send_password_reset_email(reset_link)
redirect_to root_url, notice: I18n.t("email_sent")
else
redirect_to new_password_reset_path, notice: I18n.t("no_user_email_exists")
@ -77,6 +77,10 @@ class PasswordResetsController < ApplicationController
end
end
def reset_link
request.base_url + edit_password_reset_path(@user.reset_token, email: @user.email)
end
# Confirms a valid user.
def valid_user
unless current_user&.email_verified && current_user.authenticated?(:reset, params[:id])

@ -31,7 +31,7 @@
<a
style="background: #467fcf;color: #ffffff; padding: 10px 15px; box-shadow: 0 2px 4px 0 rgba(0,0,0,.25);border: 1px solid transparent;text-decoration:none;"
href="<%= edit_password_reset_url(@user.reset_token, email: @user.email, host: @url) %>">
href="<%= @url %>">
Reset Password
</a>

@ -21,7 +21,7 @@ Password Reset
It seems like you forgot your password for <%= t('bigbluebutton') %>
If this is true, please click the link below to reset your password:
<%= edit_password_reset_url(@user.reset_token,email: @user.email, host: @url) %>
<%= @url %>
This link will expire in two hours.

@ -1,4 +1,20 @@
# frozen_string_literal: true
class UserMailerPreview < ActionMailer::Preview
# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/password_reset
def password_reset
user = User.first
user.reset_token = User.new_token
url = "http://example.com" + "/password_resets/" + user.reset_token + "/edit?email=" + user.email
UserMailer.password_reset(user, url)
end
# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/verify_email
def verify_email
user = User.first
url = "http://example.com" + "/u/verify/confirm/" + user.uid
UserMailer.verify_email(user, url)
end
end