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

Update email auth to use a common OnRuby sender #1079

Merged
merged 1 commit into from
Nov 5, 2024
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
3 changes: 1 addition & 2 deletions app/controllers/concerns/with_email_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ def email_login
email = normalize_email(params[:email])
if email.present? && valid_looking_email?(email)
token = EmailAuthToken.generate(email)
from = Whitelabel[:email]
label_name = t("label.#{Whitelabel[:label_id]}.name")
label_link = Whitelabel[:canonical_url]
UserMailer.login_link(email, token, from, I18n.locale,
UserMailer.login_link(email, token, I18n.locale,
label_name, label_link).deliver_later

redirect_to root_path, notice: t('email_auth.email_sent', email:)
Expand Down
8 changes: 5 additions & 3 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
# Original author: https://github.com/phoet

class UserMailer < ApplicationMailer
def login_link(email, token, from, locale, label_name, label_link) # rubocop:disable Metrics/ParameterLists
COMMON_SENDER = '[email protected]'

def login_link(email, token, locale, label_name, label_link)
@token = token
@from = from
@label_name = label_name
@label_link = label_link

I18n.with_locale(locale) do
mail from: @from, to: email, subject: t('email_auth.subject', label: label_name)
mail from: COMMON_SENDER, to: email,
subject: t('email_auth.subject', label: label_name)
end
end
end
5 changes: 2 additions & 3 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
describe UserMailer do
describe '#login_link' do
subject(:mail) do
described_class.login_link(email, token, from, locale, label_name, label_link).deliver_now
described_class.login_link(email, token, locale, label_name, label_link).deliver_now
end

let(:email) { '[email protected]' }
let(:token) { '12345678' }
let(:from) { '[email protected]' }
let(:locale) { :en }
let(:label_name) { 'My RUG' }
let(:label_link) { 'http://rug.org' }

it 'renders the headers' do
expect(mail.subject).to eq('Login to My RUG')
expect(mail.to).to eq([email])
expect(mail.from).to eq([from])
expect(mail.from).to eq([UserMailer::COMMON_SENDER])
end

it 'renders the body' do
Expand Down
Loading