Merge branch 'fix/masto-put-settings' into 'develop'
[akkoma] / lib / pleroma / emails / user_email.ex
1 defmodule Pleroma.UserEmail do
2 @moduledoc "User emails"
3
4 import Swoosh.Email
5
6 alias Pleroma.Web.{Endpoint, Router}
7
8 defp instance_config, do: Pleroma.Config.get(:instance)
9
10 defp instance_name, do: instance_config()[:name]
11
12 defp sender do
13 {instance_name(), instance_config()[:email]}
14 end
15
16 defp recipient(email, nil), do: email
17 defp recipient(email, name), do: {name, email}
18
19 def password_reset_email(user, password_reset_token) when is_binary(password_reset_token) do
20 password_reset_url =
21 Router.Helpers.util_url(
22 Endpoint,
23 :show_password_reset,
24 password_reset_token
25 )
26
27 html_body = """
28 <h3>Reset your password at #{instance_name()}</h3>
29 <p>Someone has requested password change for your account at #{instance_name()}.</p>
30 <p>If it was you, visit the following link to proceed: <a href="#{password_reset_url}">reset password</a>.</p>
31 <p>If it was someone else, nothing to worry about: your data is secure and your password has not been changed.</p>
32 """
33
34 new()
35 |> to(recipient(user.email, user.name))
36 |> from(sender())
37 |> subject("Password reset")
38 |> html_body(html_body)
39 end
40
41 def user_invitation_email(
42 user,
43 %Pleroma.UserInviteToken{} = user_invite_token,
44 to_email,
45 to_name \\ nil
46 ) do
47 registration_url =
48 Router.Helpers.redirect_url(
49 Endpoint,
50 :registration_page,
51 user_invite_token.token
52 )
53
54 html_body = """
55 <h3>You are invited to #{instance_name()}</h3>
56 <p>#{user.name} invites you to join #{instance_name()}, an instance of Pleroma federated social networking platform.</p>
57 <p>Click the following link to register: <a href="#{registration_url}">accept invitation</a>.</p>
58 """
59
60 new()
61 |> to(recipient(to_email, to_name))
62 |> from(sender())
63 |> subject("Invitation to #{instance_name()}")
64 |> html_body(html_body)
65 end
66 end