Skip to content

Commit

Permalink
AO3-4301 I18n the password reset email (#2116)
Browse files Browse the repository at this point in the history
* Reset password email

* .html_safe is needed

* Tidy subject up

* Fix typo

* Short locale keys and a bit of a test
  • Loading branch information
zz9pzza authored and sarken committed Jan 16, 2017
1 parent c351988 commit c3df282
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Expand Up @@ -244,7 +244,7 @@ def reset_password(user_id, activation_code)
I18n.with_locale(Locale.find(@user.preference.preferred_locale).iso) do
mail(
to: @user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Generated password"
subject: t('user_mailer.reset_password.subject', app_name: ArchiveConfig.APP_SHORT_NAME)
)
end
ensure
Expand Down
10 changes: 3 additions & 7 deletions app/views/user_mailer/reset_password.html.erb
@@ -1,11 +1,7 @@
<% content_for :message do %>
<%= style_bold(@user.login) %>, the following generated password has been created for you: <%= style_bold(@password) %>
<p><%= t('.part1', user: style_bold(@user.login), password: style_bold(@password)).html_safe %></p>

<p>
After you log in using this generated password you will be asked to change your password to something you can remember. If you do not use this generated password within a week, it will expire, and you will have to request a new one.
</p>
<p><%= t '.part2' %></p>

<p>
If you did not request this password reset, you may ignore this email and your previous password will continue to work.
</p>
<p><%= t '.part3' %></p>
<% end %>
7 changes: 4 additions & 3 deletions app/views/user_mailer/reset_password.text.erb
@@ -1,7 +1,8 @@
<% content_for :message do %>
<%= @user.login %>, the following generated password has been created for you: <%= @password %>
<%= t '.part1', user: @user.login, password: @password %>
After you log in using this generated password you will be asked to change your password to something you can remember. If you do not use this generated password within a week, it will expire, and you will have to request a new one.
<%= t '.part2' %>
<%= t '.part3' %>
If you did not request this password reset, you may ignore this email and your previous password will continue to work.
<% end %>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Expand Up @@ -53,6 +53,11 @@ en:
friend at %{invitation_page}.
Cheers,
%{archive_name}
reset_password:
subject: "[%{app_name}] Generated password"
part1: "%{user}, the following generated password has been created for you: %{password}"
part2: "After you log in using this generated password you will be asked to change your password to something you can remember. If you do not use this generated password within a week, it will expire, and you will have to request a new one."
part3: "If you did not request this password reset, you may ignore this email and your previous password will continue to work."
signup_notification:
subject: "[%{app_name}] Confirmation"
faq: "FAQ"
Expand Down
3 changes: 3 additions & 0 deletions features/users/authenticate_users.feature
Expand Up @@ -19,6 +19,9 @@ Feature: User Authentication
When I fill in "reset_password_for" with "sam"
And I press "Reset Password"
Then 1 email should be delivered
And the email should contain "the following generated password has been created for you"
And the email should contain "sam"
And the email should not contain "translation missing"

# old password should still work
When I am on the homepage
Expand Down

0 comments on commit c3df282

Please sign in to comment.