Skip to content

Commit

Permalink
Deliver password reset email inline (#882)
Browse files Browse the repository at this point in the history
This commit changes the delivery behavior of the password reset email:

Before, it queued the email for later delivery.
Now, it delivers the email immediately.

The queue can be backed up, have no running workers, or other issues.
These issues can cause delay or no email delivery,
leading the user to abandon the site or contact support.
In the case of no delivery, there is also no error trace.

Inlining delivery also lets the programmer handle error cases such as
the email delivery service experiencing downtime or degraded service
or the email delivery service responding that it can't deliver the email
(such as a badly formatted or non-existent email address).
Handling these errors can help the user fix their own typos, etc.

Lastly, a project that integrates Clearance no longer needs to have
a background job process in their project.

https://api.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
  • Loading branch information
croaky authored Aug 14, 2020
1 parent 05db2df commit dcb96dc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
18 changes: 0 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,6 @@ and `password` attributes. Over-riding the `email_optional?` or
`skip_password_validation?` methods to return `true` will disable those
validations from being added.

### Deliver Email in Background Job

Clearance has a password reset mailer. If you are using Rails 4.2 and Clearance
1.6 or greater, Clearance will use ActiveJob's `deliver_later` method to
automatically take advantage of your configured queue.

If you are using an earlier version of Rails, you can override the
`Clearance::Passwords` controller and define the behavior you need in the
`deliver_email` method.

```ruby
class PasswordsController < Clearance::PasswordsController
def deliver_email(user)
ClearanceMailer.delay.change_password(user)
end
end
```

## Extending Sign In

By default, Clearance will sign in any user with valid credentials. If you need
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/clearance/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def update
private

def deliver_email(user)
mail = ::ClearanceMailer.change_password(user)
mail.deliver_later
::ClearanceMailer.change_password(user).deliver_now
end

def password_from_password_reset_params
Expand Down

0 comments on commit dcb96dc

Please sign in to comment.