Skip to content

Commit

Permalink
Merge pull request #657 from eyra/outlook-safelink
Browse files Browse the repository at this point in the history
Outlook Safelink
  • Loading branch information
mellelieuwes authored Mar 22, 2024
2 parents 44f7cf2 + 193989f commit edfd210
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 44 deletions.
50 changes: 36 additions & 14 deletions core/lib/core_web/live/user/confirm_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,32 @@ defmodule CoreWeb.User.ConfirmToken do
alias Core.Accounts
alias Core.Accounts.User

require Logger

def mount(%{"token" => token}, _session, socket) do
require_feature(:password_sign_in)
connected? = Phoenix.LiveView.connected?(socket)

{:ok,
socket
|> assign(
failed: false,
token: token
)
|> confirm_user(connected?)}

{
:ok,
socket
|> assign(
failed: false,
token: token
)
|> update_confirm_button()
}
end

defp confirm_user(socket, false) do
# Only confirm user when socket is connected to prevent early invalidation of token.
# https://github.com/eyra/mono/issues/615
socket
defp update_confirm_button(socket) do
confirm_button = %{
action: %{type: :send, event: "confirm"},
face: %{type: :primary, label: dgettext("eyra-account", "confirm.button")}
}

assign(socket, confirm_button: confirm_button)
end

defp confirm_user(%{assigns: %{token: token}} = socket, true) do
defp confirm_user(%{assigns: %{token: token}} = socket) do
case Accounts.confirm_user(token) do
{:ok, user} ->
handle_succeeded(socket, user)
Expand All @@ -41,12 +47,16 @@ defmodule CoreWeb.User.ConfirmToken do
end

defp handle_succeeded(socket, %{email: email}) do
Logger.notice("Confirm user: handle_succeeded #{email}")

socket
|> put_flash(:info, dgettext("eyra-user", "account.activated.successfully"))
|> redirect(to: ~p"/user/signin?email=#{email}")
end

defp handle_failed(socket) do
Logger.notice("Confirm user: handle_failed")

assign(socket,
failed: true,
status: :invalid,
Expand All @@ -58,6 +68,11 @@ defmodule CoreWeb.User.ConfirmToken do
{:noreply, socket}
end

@impl true
def handle_event("confirm", _, socket) do
{:noreply, confirm_user(socket)}
end

@impl true
def handle_event("resend-token", %{"user" => %{"email" => email}}, socket) do
case User.valid_email_changeset(email) do
Expand Down Expand Up @@ -112,6 +127,13 @@ defmodule CoreWeb.User.ConfirmToken do
<.email_input form={form} field={:email} label_text={dgettext("eyra-user", "confirm.token.email.label")} />
<Button.submit label={dgettext("eyra-account", "confirm.token.resend_button")} />
</.form>
<% else %>
<Text.title1><%= dgettext("eyra-account", "activation.confirm.title") %></Text.title1>
<Text.body><%= dgettext("eyra-account", "activation.confirm.body") %></Text.body>
<.spacing value="M" />
<.wrap>
<Button.dynamic {@confirm_button} />
</.wrap>
<% end %>
</Area.sheet>
</.stripped>
Expand Down
14 changes: 13 additions & 1 deletion core/priv/gettext/en/LC_MESSAGES/eyra-account.po
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ msgstr "Sign in"

#, elixir-autogen, elixir-format, fuzzy
msgid "await.confirmation.description"
msgstr "Your account has been created. We send you an activation email. Please click the link in the email to activate your account."
msgstr "Your account has been created. We have sent you an activation email. Please click the link in the email to activate your account."

#, elixir-autogen, elixir-format
msgid "activation.failed.body"
Expand All @@ -137,3 +137,15 @@ msgstr "Your account might already have been activated or the activation link is
#, elixir-autogen, elixir-format
msgid "activation.failed.title"
msgstr "Account activation"

#, elixir-autogen, elixir-format, fuzzy
msgid "activation.confirm.body"
msgstr "Click the button below to activate your account. You will be forwarded to the sign in page."

#, elixir-autogen, elixir-format, fuzzy
msgid "activation.confirm.title"
msgstr "Account activation"

#, elixir-autogen, elixir-format
msgid "confirm.button"
msgstr "Activate"
10 changes: 6 additions & 4 deletions core/priv/gettext/en/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ msgstr "<h1>Privacy statement URL</h1> Use the URL below to refer to the uploade
#, elixir-autogen, elixir-format
msgid "privacy.title"
msgstr "Privacy"

#, elixir-autogen, elixir-format
msgid "tabbar.item.monitor"
msgstr "Monitor"

Expand Down Expand Up @@ -336,10 +338,10 @@ msgstr "Declined consent"
msgid "settings.general.title"
msgstr "General"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.subject_count.label"
msgstr "Expected number of participants"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.language.label"
msgstr "Language setting for participants"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.subject_count.label"
msgstr "Expected number of participants"
10 changes: 5 additions & 5 deletions core/priv/gettext/en/LC_MESSAGES/eyra-user.po
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ msgstr "Send instructions"

#, elixir-autogen, elixir-format
msgid "password_reset.reset_password_button"
msgstr "Change password"
msgstr "Create"

#, elixir-autogen, elixir-format
msgid "user.password_reset.title"
msgstr "Change password"
msgstr "New password"

#, elixir-autogen, elixir-format
msgid "Invalid email or password"
Expand All @@ -48,19 +48,19 @@ msgstr "Register"

#, elixir-autogen, elixir-format
msgid "reset.link"
msgstr "Change password"
msgstr "Forgot password?"

#, elixir-autogen, elixir-format, fuzzy
msgid "user.password_reset.flash"
msgstr "Password change requested. If your email address is registered, you will receive instructions shortly."
msgstr "New password requested. If your email address is registered, you will receive instructions shortly."

#, elixir-autogen, elixir-format, fuzzy
msgid "Invalid email"
msgstr "Invalid email address"

#, elixir-autogen, elixir-format, fuzzy
msgid "confirm.token.flash"
msgstr "If your email address is registered, but not yet confirmed, you will receive email instructions shortly."
msgstr "If your email address is registered, but not yet confirmed, you will receive instructions shortly."

#, elixir-autogen, elixir-format
msgid "Signed out successfully"
Expand Down
12 changes: 12 additions & 0 deletions core/priv/gettext/eyra-account.pot
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "activation.failed.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "activation.confirm.body"
msgstr ""

#, elixir-autogen, elixir-format
msgid "activation.confirm.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "confirm.button"
msgstr ""
3 changes: 3 additions & 0 deletions core/priv/gettext/eyra-assignment.pot
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ msgstr ""

#, elixir-autogen, elixir-format
msgid "privacy.title"
msgstr ""

#, elixir-autogen, elixir-format
msgid "tabbar.item.monitor"
msgstr ""

Expand Down
12 changes: 12 additions & 0 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-account.po
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,15 @@ msgstr "Jouw account activatie link is ongeldig of verlopen. Voer je e-mailadres
#, elixir-autogen, elixir-format
msgid "activation.failed.title"
msgstr "Activatie mislukt"

#, elixir-autogen, elixir-format, fuzzy
msgid "activation.confirm.body"
msgstr "Klik op de knop hieronder om uw account te activeren. U wordt doorgestuurd naar het inlogscherm."

#, elixir-autogen, elixir-format, fuzzy
msgid "activation.confirm.title"
msgstr "Account activatie"

#, elixir-autogen, elixir-format
msgid "confirm.button"
msgstr "Activeer"
9 changes: 5 additions & 4 deletions core/priv/gettext/nl/LC_MESSAGES/eyra-assignment.po
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ msgstr "<h1>Privacyverklaring URL</h1> Gebruik de URL hieronder om naar de geüp
msgid "privacy.title"
msgstr "Privacy"

#, elixir-autogen, elixir-format
msgid "tabbar.item.monitor"
msgstr "Monitor"

Expand Down Expand Up @@ -337,10 +338,10 @@ msgstr "Toestemming geweigerd"
msgid "settings.general.title"
msgstr "General"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.subject_count.label"
msgstr "Verwachtte aantal deelnemers"

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.language.label"
msgstr ""

#, elixir-autogen, elixir-format, fuzzy
msgid "settings.subject_count.label"
msgstr "Verwachtte aantal deelnemers"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Thank you for creating an account on Next. You are only one step removed from being able to use the platform.
<br /><br />
Click <a href="<%= @url %>">here</a> to sign in. Your account will be activated and ready to use.
Click <a href="<%= @url %>">here</a> to activate your account.
<br /><br />
If you did not register an account on Next, you can discard this email.
<br /><br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Activate your account

Thank you for creating an account on Next. You are only one step removed from being able to use the platform.

To sign in, click on this link <%= @url %>. Your account will be activated and ready to use.
To activate your account, click on this link <%= @url %>.

If you did not register an account on Next, you can discard this email.

Expand Down
6 changes: 3 additions & 3 deletions core/systems/email/email/reset_password_instructions.html.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Change password</h1>
<h1>New password</h1>

You have requested a password change on Next. Click <a href="<%= @url %>">here</a> to create a new password.
If you did not request a password change, you can discard this email.
You have requested a new password for your Next account. Click <a href="<%= @url %>">here</a> to create a new password.
If you did not request a new password, you can discard this email.
<br /><br />
Kind regards,
<br /><br />
Expand Down
6 changes: 3 additions & 3 deletions core/systems/email/email/reset_password_instructions.text.eex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Password change
New password

You have requested a password change on Next. Click the following link to create a new password: <%= @url %>.
If you did not request a password change, you can discard this email.
You have requested a new password for your Next account. Click the following link to create a new password: <%= @url %>.
If you did not request a new password, you can discard this email.

Kind regards,

Expand Down
Loading

0 comments on commit edfd210

Please sign in to comment.