Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SD-934] Use email template in reset password email #504

Merged
merged 5 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/mailers/spree/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def reset_password_instructions(user, token, *_args)
@locale = @current_store.has_attribute?(:default_locale) ? @current_store.default_locale : I18n.default_locale
I18n.locale = @locale if @locale.present?
@edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url)
@user = user

mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
end
Expand Down
20 changes: 20 additions & 0 deletions app/views/spree/user_mailer/reset_password_instructions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>
<%= Spree.t('user_mailer.reset_password_instructions.welcome', email: @user.email) %>
</h1>
<p>
<%= Spree.t('user_mailer.reset_password_instructions.instructions_1', { store_name: @current_store.name }) %>
</p>
<p>
<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
</p>
<p class="body-action">
<a href="<%= @edit_password_reset_url %>" class="button button--green"><%= Spree.t('user_mailer.reset_password_instructions.button') %></a>
</p>
<p>
<%= Spree.t('user_mailer.reset_password_instructions.instructions_3') %>
</p>
<p>
<%= Spree.t('user_mailer.reset_password_instructions.thanks') %>
<br />
<%= Spree.t('user_mailer.reset_password_instructions.store_team', { store_name: @current_store.name }) %>
</p>
11 changes: 9 additions & 2 deletions app/views/spree/user_mailer/reset_password_instructions.text.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<%= Spree.t('user_mailer.reset_password_instructions.instructions_1') %>
<%= Spree.t('user_mailer.reset_password_instructions.welcome', email: @user.email) %>

<%= Spree.t('user_mailer.reset_password_instructions.instructions_1', { store_name: @current_store.name }) %>
<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>

<%= Spree.t('user_mailer.reset_password_instructions.button') %>
<%= @edit_password_reset_url %>

<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
<%= Spree.t('user_mailer.reset_password_instructions.instructions_3') %>

<%= Spree.t('user_mailer.reset_password_instructions.thanks') %>
<%= Spree.t('user_mailer.reset_password_instructions.store_team', { store_name: @current_store.name }) %>
9 changes: 7 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ en:
credit_balance: Store Credit Balance
user_mailer:
reset_password_instructions:
instructions_1: "A request to reset your password has been made.\nIf you did not make this request, simply ignore this email.\n\nIf you did make this request just click the link below:"
instructions_2: "If the above URL does not work try copying and pasting it into your browser.\nIf you continue to have problems please feel free to contact us."
welcome: "Hi %{email}"
instructions_1: "A request to reset the password for your %{store_name} account has been made."
instructions_2: Click the button below to reset it.
instructions_3: If you did not request a password change ignore this email or contact us.
button: Reset your password
thanks: Thank you,
store_team: "%{store_name} Team"
przemosk marked this conversation as resolved.
Show resolved Hide resolved
confirmation_instructions:
welcome: "Welcome %{email}!"
confirm: "You can confirm your account email through the url below:"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
# The 'plain-text' version is sent in the email and there's one way to get that!
reset_password_email = ActionMailer::Base.deliveries.first
token_url_regex = /^http:\/\/www.example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
token = token_url_regex.match(reset_password_email.body.to_s)[1]
token = token_url_regex.match(reset_password_email.body.encoded)[1]

visit spree.edit_spree_user_password_path(reset_password_token: token)
visit spree.edit_spree_user_password_path(reset_password_token: token).tr("%0D","")
fill_in 'Password', with: 'password'
fill_in 'Password Confirmation', with: 'password'
click_button 'Update'
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

context 'body includes' do
it 'password reset url' do
expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
expect(@message.body.encoded).to include "http://#{store.url}/user/spree_user/password/edit"
end
end
end
Expand Down