Allow to edit account email and delete account
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -61,9 +61,10 @@ defmodule Mobilizon.Web.Email.User do
|
||||
with %User{} = user <- Users.get_user_by_activation_token(token),
|
||||
{:ok, %User{} = user} <-
|
||||
Users.update_user(user, %{
|
||||
"confirmed_at" => DateTime.utc_now() |> DateTime.truncate(:second),
|
||||
"confirmation_sent_at" => nil,
|
||||
"confirmation_token" => nil
|
||||
confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second),
|
||||
confirmation_sent_at: nil,
|
||||
confirmation_token: nil,
|
||||
email: user.unconfirmed_email || user.email
|
||||
}) do
|
||||
Logger.info("User #{user.email} has been confirmed")
|
||||
{:ok, user}
|
||||
@@ -141,6 +142,48 @@ defmodule Mobilizon.Web.Email.User do
|
||||
end
|
||||
end
|
||||
|
||||
def send_email_reset_old_email(
|
||||
%User{locale: user_locale, email: email, unconfirmed_email: unconfirmed_email} = _user,
|
||||
_locale \\ "en"
|
||||
) do
|
||||
Gettext.put_locale(user_locale)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"Mobilizon on %{instance}: email changed",
|
||||
instance: Config.instance_name()
|
||||
)
|
||||
|
||||
Email.base_email(to: email, subject: subject)
|
||||
|> assign(:locale, user_locale)
|
||||
|> assign(:subject, subject)
|
||||
|> assign(:new_email, unconfirmed_email)
|
||||
|> render(:email_changed_old)
|
||||
end
|
||||
|
||||
def send_email_reset_new_email(
|
||||
%User{
|
||||
locale: user_locale,
|
||||
unconfirmed_email: unconfirmed_email,
|
||||
confirmation_token: confirmation_token
|
||||
} = _user,
|
||||
_locale \\ "en"
|
||||
) do
|
||||
Gettext.put_locale(user_locale)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"Mobilizon on %{instance}: confirm your email address",
|
||||
instance: Config.instance_name()
|
||||
)
|
||||
|
||||
Email.base_email(to: unconfirmed_email, subject: subject)
|
||||
|> assign(:locale, user_locale)
|
||||
|> assign(:subject, subject)
|
||||
|> assign(:token, confirmation_token)
|
||||
|> render(:email_changed_new)
|
||||
end
|
||||
|
||||
@spec we_can_send_email(User.t(), atom) :: :ok | {:error, :email_too_soon}
|
||||
defp we_can_send_email(%User{} = user, key) do
|
||||
case Map.get(user, key) do
|
||||
|
||||
@@ -130,6 +130,8 @@ defmodule Mobilizon.Web.Router do
|
||||
as: "participation_email_confirmation"
|
||||
)
|
||||
|
||||
get("/validate/email/:token", PageController, :index, as: "user_email_validation")
|
||||
|
||||
get("/interact", PageController, :interact)
|
||||
end
|
||||
|
||||
|
||||
75
lib/web/templates/email/email_changed_new.html.eex
Normal file
75
lib/web/templates/email/email_changed_new.html.eex
Normal file
@@ -0,0 +1,75 @@
|
||||
<!-- HERO -->
|
||||
<tr>
|
||||
<td bgcolor="#424056" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #111111; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
|
||||
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
|
||||
<%= gettext "Verify email address" %>
|
||||
</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
<!-- COPY BLOCK -->
|
||||
<tr>
|
||||
<td bgcolor="#f4f4f4" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
|
||||
<p style="margin: 0;">
|
||||
<%= gettext "Confirm the new address to change your email." %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#424056">
|
||||
<a href="<%= user_email_validation_url(Mobilizon.Web.Endpoint, :index, @token) %>" target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #424056; display: inline-block;">
|
||||
<%= gettext "Verify email address" %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #777777; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 20px;" >
|
||||
<p style="margin: 0">
|
||||
<%= gettext "If this change wasn't initiated by you, please ignore this email. The email address for the Mobilizon account won't change until you access the link above." %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
10
lib/web/templates/email/email_changed_new.text.eex
Normal file
10
lib/web/templates/email/email_changed_new.text.eex
Normal file
@@ -0,0 +1,10 @@
|
||||
<%= gettext "Verify email address" %>
|
||||
|
||||
==
|
||||
|
||||
<%= gettext "Confirm the new address to change your email." %>
|
||||
|
||||
<%= user_email_validation_url(Mobilizon.Web.Endpoint, :index, @token) %>
|
||||
|
||||
|
||||
<%= gettext "If this change wasn't initiated by you, please ignore this email. The email address for the Mobilizon account won't change until you access the link above." %>
|
||||
73
lib/web/templates/email/email_changed_old.html.eex
Normal file
73
lib/web/templates/email/email_changed_old.html.eex
Normal file
@@ -0,0 +1,73 @@
|
||||
<!-- HERO -->
|
||||
<tr>
|
||||
<td bgcolor="#424056" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #111111; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; line-height: 48px;">
|
||||
<h1 style="font-size: 48px; font-weight: 400; margin: 0;">
|
||||
<%= gettext "New email address" %>
|
||||
</h1>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
<!-- COPY BLOCK -->
|
||||
<tr>
|
||||
<td bgcolor="#f4f4f4" align="center" style="padding: 0px 10px 0px 10px;">
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
<table align="center" border="0" cellspacing="0" cellpadding="0" width="600">
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;" >
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 0px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;" >
|
||||
<p style="margin: 0;">
|
||||
<%= gettext "The email address for your account on %{host} is being changed to:", host: @instance[:name] %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<%= @new_email %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #777777; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 20px;" >
|
||||
<p style="margin: 0">
|
||||
<%= gettext "If you did not ask to change your email, it is likely that someone has gained access to your account. Please change your password immediately or contact the server admin if you're locked out of your account." %>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
9
lib/web/templates/email/email_changed_old.text.eex
Normal file
9
lib/web/templates/email/email_changed_old.text.eex
Normal file
@@ -0,0 +1,9 @@
|
||||
<%= gettext "New email address" %>
|
||||
|
||||
==
|
||||
|
||||
<%= gettext "The email address for your account on %{host} is being changed to:", host: @instance[:name] %>
|
||||
|
||||
<%= @new_email %>
|
||||
|
||||
<%= gettext "If you did not ask to change your email, it is likely that someone has gained access to your account. Please change your password immediately or contact the server admin if you're locked out of your account." %>
|
||||
Reference in New Issue
Block a user