-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from unboxed/add-password-reset-configuration
Configure Devise's password recovery feature
- Loading branch information
Showing
17 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Admin | ||
class PasswordsController < Devise::PasswordsController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Admin | ||
class Mailer < Devise::Mailer | ||
def devise_mail(record, action, opts = {}) | ||
initialize_from_record(record) | ||
view_mail(template_id, headers_for(action, opts)) | ||
end | ||
|
||
private | ||
|
||
def template_id | ||
ENV.fetch("NOTIFY_DEVISE_TEMPLATE_ID") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: '[email protected]' | ||
class ApplicationMailer < Mail::Notify::Mailer | ||
default from: '[email protected]' | ||
layout 'mailer' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class User < ApplicationRecord | ||
devise :database_authenticatable, :rememberable, :validatable | ||
devise :database_authenticatable, :rememberable, :validatable, :recoverable | ||
|
||
def first_name | ||
name.to_s.split(/\s+/).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Hello <%= @resource.first_name %>, | ||
|
||
We're contacting you to notify you that your password has been changed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hello <%= @resource.first_name %>, | ||
|
||
Someone has requested a link to change your password. You can do this through the link below. | ||
|
||
[Change my password](<%= edit_password_url(@resource, reset_password_token: @token) %>) | ||
|
||
If you didn't request this, please ignore this email. | ||
|
||
Your password won't change until you access the link above and create a new one. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%= form_for(resource, as: resource_name, url: password_path(resource_name), method: :put) do |f| %> | ||
<%= error_summary resource %> | ||
|
||
<%= f.hidden_field :reset_password_token %> | ||
|
||
<div class="govuk-form-group"> | ||
<fieldset class="govuk-fieldset"> | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l"> | ||
<h1 class="govuk-fieldset__heading">Change your password</h1> | ||
</legend> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.label :password, "New password", class: "govuk-label" %> | ||
<%= f.password_field :password, class: "govuk-input govuk-input--width-30", autofocus: true, autocomplete: "new-password" %> | ||
</div> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.label :password_confirmation, "Confirm new password", class: "govuk-label" %> | ||
<%= f.password_field :password_confirmation, class: "govuk-input govuk-input--width-30", autofocus: true, autocomplete: "new-password" %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= f.submit "Change my password", class: "govuk-button", data: { module: "govuk-button" } %> | ||
</div> | ||
|
||
<p class="govuk-body"> | ||
<%= link_to "Sign in", new_session_path(resource_name), class: "govuk-link" %> | ||
</p> | ||
</fieldset> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<% if flash[:alert] %> | ||
<div class="govuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1" data-module="govuk-error-summary"> | ||
<h2 class="govuk-error-summary__title" id="error-summary-title"> | ||
There was a problem recovering your password | ||
</h2> | ||
<div class="govuk-error-summary__body"> | ||
<ul class="govuk-list govuk-error-summary__list"> | ||
<li> | ||
<a href="#admin_email"><%= alert %></a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<% end %> | ||
|
||
<%= form_for(resource, as: resource_name, url: password_path(resource_name)) do |f| %> | ||
<%= error_summary resource %> | ||
|
||
<div class="govuk-form-group"> | ||
<fieldset class="govuk-fieldset"> | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l"> | ||
<h1 class="govuk-fieldset__heading">Forgot your password?</h1> | ||
</legend> | ||
|
||
<div class="govuk-form-group"> | ||
<%= f.label :email, "Email address", class: "govuk-label" %> | ||
<%= f.text_field :email, class: "govuk-input govuk-input--width-30", spellcheck: false, autofocus: true, inputmode: "email", autocomplete: "email" %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= f.submit "Send me password reset instructions", class: "govuk-button", data: { module: "govuk-button" } %> | ||
</div> | ||
|
||
<p class="govuk-body"> | ||
<%= link_to "Sign in", new_session_path(resource_name), class: "govuk-link" %> | ||
</p> | ||
</fieldset> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ | |
# Configure the e-mail address which will be shown in Devise::Mailer, | ||
# note that it will be overwritten if you use your own mailer class | ||
# with default "from" parameter. | ||
config.mailer_sender = '[email protected]' | ||
config.mailer_sender = '[email protected]' | ||
|
||
# Configure the class responsible to send e-mails. | ||
# config.mailer = 'Devise::Mailer' | ||
config.mailer = 'Admin::Mailer' | ||
|
||
# Configure the parent class responsible to send e-mails. | ||
# config.parent_mailer = 'ActionMailer::Base' | ||
config.parent_mailer = 'ApplicationMailer' | ||
|
||
# ==> ORM configuration | ||
# Load and configure the ORM. Supports :active_record (default) and | ||
|
@@ -90,7 +90,7 @@ | |
# It will change confirmation, password recovery and other workflows | ||
# to behave the same regardless if the e-mail provided was right or wrong. | ||
# Does not affect registerable. | ||
# config.paranoid = true | ||
config.paranoid = true | ||
|
||
# By default Devise will store the user in session. You can skip storage for | ||
# particular strategies by setting this option. | ||
|
@@ -132,7 +132,7 @@ | |
# config.send_email_changed_notification = false | ||
|
||
# Send a notification email when the user's password is changed. | ||
# config.send_password_change_notification = false | ||
config.send_password_change_notification = true | ||
|
||
# ==> Configuration for :confirmable | ||
# A period that the user is allowed to access the website even without | ||
|
@@ -228,7 +228,7 @@ | |
|
||
# When set to false, does not sign a user in automatically after their password is | ||
# reset. Defaults to true, so a user is signed in automatically after a reset. | ||
# config.sign_in_after_reset_password = true | ||
config.sign_in_after_reset_password = false | ||
|
||
# ==> Configuration for :encryptable | ||
# Allow you to use another hashing or encryption algorithm besides bcrypt (default). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters