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

mailer: allow configuration option to change the Mailer's superclass #82

Merged
merged 1 commit into from
Apr 30, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Added

- Option to customize mailer inheritance with a new configuration `parent_mailer` ([#82](https://github.com/mikker/passwordless/pull/82))

## 0.9.0 (2019-12-19)

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ The default values are shown below. It's recommended to only include the ones th

```ruby
Passwordless.default_from_address = "[email protected]"
Passwordless.parent_mailer = "ActionMailer::Base"
Passwordless.token_generator = Passwordless::UrlSafeBase64Generator.new # Used to generate magic link tokens.
Passwordless.restrict_token_reuse = false # By default a magic link token can be used multiple times.
Passwordless.redirect_back_after_sign_in = true # When enabled the user will be redirected to their previous page, or a page specified by the `destination_path` query parameter, if available.
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/passwordless/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Passwordless
# The mailer responsible for sending Passwordless' mails.
class Mailer < ActionMailer::Base
class Mailer < Passwordless.parent_mailer.constantize
default from: Passwordless.default_from_address

# Sends a magic link (secret token) email.
Expand All @@ -11,7 +11,7 @@ def magic_link(session)
@session = session

@magic_link = send(Passwordless.mounted_as)
.token_sign_in_url(session.token)
.token_sign_in_url(session.token)

email_field = @session.authenticatable.class.passwordless_email_field
mail(
Expand Down
1 change: 1 addition & 0 deletions lib/passwordless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# The main Passwordless module
module Passwordless
mattr_accessor(:parent_mailer) { "ActionMailer::Base" }
mattr_accessor(:default_from_address) { "[email protected]" }
mattr_accessor(:token_generator) { UrlSafeBase64Generator.new }
mattr_accessor(:restrict_token_reuse) { false }
Expand Down