Skip to content

Commit 03feb9a

Browse files
authored
Fix email change confirmation (#172)
* Update translation files I run `mix gettext.extract` and `mix gettext.merge priv/gettext` as it seems that the files were somewhat outdated. * Fix email change confirmation Send the confirmation email to the new address * Tweak email change confirmation email * Run ./dev.sh format
1 parent 0ccf3ae commit 03feb9a

File tree

14 files changed

+1737
-1379
lines changed

14 files changed

+1737
-1379
lines changed

lib/claper/accounts/user_notifier.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Claper.Accounts.UserNotifier do
5252
Deliver instructions to update a user email.
5353
"""
5454
def deliver_update_email_instructions(user, url) do
55-
Claper.Workers.Mailers.new_update_email(user.id, url) |> Oban.insert()
55+
Claper.Workers.Mailers.new_update_email(user.email, url) |> Oban.insert()
5656

5757
{:ok, :enqueued}
5858
end

lib/claper/workers/mailers.ex

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ defmodule Claper.Workers.Mailers do
66

77
@impl Oban.Worker
88
def perform(%Oban.Job{args: %{"type" => type, "user_id" => user_id, "url" => url}})
9-
when type in ["confirm", "reset", "update_email"] do
9+
when type in ["confirm", "reset"] do
1010
user = Claper.Accounts.get_user!(user_id)
1111

1212
email =
1313
case type do
1414
"confirm" -> UserNotifier.confirm(user, url)
1515
"reset" -> UserNotifier.reset(user, url)
16-
"update_email" -> UserNotifier.update_email(user, url)
1716
end
1817

1918
Mailer.deliver(email)
2019
end
2120

21+
def perform(%Oban.Job{
22+
args: %{"type" => "update_email", "new_email" => new_email, "url" => url}
23+
}) do
24+
email = UserNotifier.update_email(new_email, url)
25+
Mailer.deliver(email)
26+
end
27+
2228
def perform(%Oban.Job{args: %{"type" => "magic", "email" => email, "url" => url}}) do
2329
email = UserNotifier.magic(email, url)
2430
Mailer.deliver(email)
@@ -50,8 +56,8 @@ defmodule Claper.Workers.Mailers do
5056
new(%{type: "reset", user_id: user_id, url: url})
5157
end
5258

53-
def new_update_email(user_id, url) do
54-
new(%{type: "update_email", user_id: user_id, url: url})
59+
def new_update_email(new_email, url) do
60+
new(%{type: "update_email", new_email: new_email, url: url})
5561
end
5662

5763
def new_magic_link(email, url) do

lib/claper_web/notifiers/user_notifier.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
2424
|> render_body("welcome.html", %{email: email})
2525
end
2626

27-
def update_email(user, url) do
27+
def update_email(new_email, url) do
2828
new()
29-
|> to(user.email)
29+
|> to(new_email)
3030
|> from(
3131
{Application.get_env(:claper, :mail) |> Keyword.get(:from_name),
3232
Application.get_env(:claper, :mail) |> Keyword.get(:from)}
3333
)
3434
|> subject(gettext("Update email instructions"))
35-
|> render_body("change.html", %{user: user, url: url})
35+
|> render_body("change.html", %{url: url})
3636
end
3737

3838
def confirm(user, url) do

lib/claper_web/templates/user_notifier/change.html.heex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
<tr>
1515
<td style="padding:0 35px;">
1616
<h1 style="color:#1e1e2d; font-weight:500; margin:0;font-size:32px;font-family:'Rubik',sans-serif;">
17-
{gettext("Confirm email")}
17+
{gettext("Confirm email change")}
1818
</h1>
1919
<span style="display:inline-block; vertical-align:middle; margin:29px 0 26px; border-bottom:1px solid #cecece; width:100px;">
2020
</span>
2121
<p style="color:#455056; font-size:15px;line-height:24px; margin:0;">
22-
{gettext("You can change your email by visiting the URL below")}
22+
{gettext("You can confirm your email change by visiting the URL below")}
2323
</p>
2424
<a
2525
href={@url}
@@ -29,7 +29,7 @@
2929
{gettext("CONFIRM EMAIL")}
3030
</a>
3131
<p style="color:#455056; font-size:15px;line-height:24px; margin-top:26px;">
32-
{gettext("If you didn't create an account with us, please ignore this.")}
32+
{gettext("If you didn't request an email change, please ignore this.")}
3333
</p>
3434
</td>
3535
</tr>

0 commit comments

Comments
 (0)