Skip to content

Commit

Permalink
Pass params to mailers
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaronixon committed Oct 8, 2024
1 parent 3369d85 commit 71cbde6
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Remove system tests
* Use native rate_limit for lockable
* Copy web_authn_controller.js instead of depend on stimulus-web-authn
* Pass params to mailers instead of `.with(...)`

## Authentication Zero 3.0.2 ##

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Identity::EmailVerificationsController < ApplicationController
end

def create
UserMailer.with(user: Current.user).email_verification.deliver_later
UserMailer.email_verification(Current.user).deliver_later
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class Identity::EmailsController < ApplicationController
end

def resend_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
UserMailer.email_verification(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Identity::PasswordResetsController < ApplicationController

def create
if @user = User.find_by(email: params[:email], verified: true)
UserMailer.with(user: @user).password_reset.deliver_later
UserMailer.password_reset(@user).deliver_later
else
render json: { error: "You can't reset your password until you verify your email" }, status: :bad_request
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class RegistrationsController < ApplicationController
end

def send_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
UserMailer.email_verification(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class Identity::EmailVerificationsController < ApplicationController
end

def send_email_verification
UserMailer.with(user: Current.user).email_verification.deliver_later
UserMailer.email_verification(Current.user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class Identity::EmailsController < ApplicationController
end

def resend_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
UserMailer.email_verification(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ class Identity::PasswordResetsController < ApplicationController
end

def send_password_reset_email
UserMailer.with(user: @user).password_reset.deliver_later
UserMailer.password_reset(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class InvitationsController < ApplicationController
end

def send_invitation_instructions
UserMailer.with(user: @user).invitation_instructions.deliver_later
UserMailer.invitation_instructions(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class RegistrationsController < ApplicationController
end

def send_email_verification
UserMailer.with(user: @user).email_verification.deliver_later
UserMailer.email_verification(@user).deliver_later
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Sessions::PasswordlessesController < ApplicationController
end

def send_passwordless_email
UserMailer.with(user: @user).passwordless.deliver_later
UserMailer.passwordless(@user).deliver_later
end

def revoke_tokens
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
class UserMailer < ApplicationMailer
def password_reset
@user = params[:user]
def password_reset(user)
@user = user
@signed_id = @user.generate_token_for(:password_reset)

mail to: @user.email, subject: "Reset your password"
end

def email_verification
@user = params[:user]
def email_verification(user)
@user = user
@signed_id = @user.generate_token_for(:email_verification)

mail to: @user.email, subject: "Verify your email"
end
<%- if passwordless? %>
def passwordless
@user = params[:user]
def passwordless(user)
@user = user
@signed_id = @user.sign_in_tokens.create.signed_id(expires_in: 1.day)

mail to: @user.email, subject: "Your sign in link"
end
<%- end -%>
<%- if invitable? %>
def invitation_instructions
@user = params[:user]
def invitation_instructions(user)
@user = user
@signed_id = @user.generate_token_for(:password_reset)

mail to: @user.email, subject: "Invitation instructions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class UserMailerTest < ActionMailer::TestCase
end

test "password_reset" do
mail = UserMailer.with(user: @user).password_reset
mail = UserMailer.password_reset(@user)
assert_equal "Reset your password", mail.subject
assert_equal [@user.email], mail.to
end

test "email_verification" do
mail = UserMailer.with(user: @user).email_verification
mail = UserMailer.email_verification(@user)
assert_equal "Verify your email", mail.subject
assert_equal [@user.email], mail.to
end
Expand Down

0 comments on commit 71cbde6

Please sign in to comment.