Skip to main content

max / makenotwork

4.8 KB · 181 lines History Blame Raw
1 //! Authentication and account action email templates.
2
3 use crate::email::EmailClient;
4 use crate::error::Result;
5
6 impl EmailClient {
7 /// Send a password reset email
8 pub async fn send_password_reset(
9 &self,
10 to_email: &str,
11 to_name: Option<&str>,
12 reset_url: &str,
13 ) -> Result<()> {
14 let subject = "Reset your password";
15 let body = format!(
16 r#"Hi{name},
17
18 You requested to reset your password. Click the link below to set a new password:
19
20 {url}
21
22 This link expires in 15 minutes. If you didn't request this, you can ignore this email.
23
24 - Makenotwork"#,
25 name = crate::email::greeting(to_name),
26 url = reset_url
27 );
28
29 self.transport.send_email(to_email, subject, &body).await
30 }
31
32 /// Send an email verification email
33 pub async fn send_verification(
34 &self,
35 to_email: &str,
36 to_name: Option<&str>,
37 verify_url: &str,
38 ) -> Result<()> {
39 let subject = "Verify your email";
40 let body = format!(
41 r#"Hi{name},
42
43 Please verify your email address by clicking the link below:
44
45 {url}
46
47 This link expires in 24 hours.
48
49 - Makenotwork"#,
50 name = crate::email::greeting(to_name),
51 url = verify_url
52 );
53
54 self.transport.send_email(to_email, subject, &body).await
55 }
56
57 /// Send an account lockout notification
58 pub async fn send_lockout_notification(
59 &self,
60 to_email: &str,
61 to_name: Option<&str>,
62 login_link_url: Option<&str>,
63 ) -> Result<()> {
64 let subject = "Security alert: Account locked";
65 let body = format!(
66 r#"Hi{name},
67
68 Your account has been temporarily locked due to multiple failed login attempts.
69
70 {login_link}
71
72 If this wasn't you, please contact support immediately.
73
74 - Makenotwork"#,
75 name = crate::email::greeting(to_name),
76 login_link = login_link_url
77 .map(|url| format!("Use this link to log in securely:\n\n{}\n\nThis link expires in 15 minutes.", url))
78 .unwrap_or_else(|| "Your account will unlock automatically in 15 minutes.".to_string())
79 );
80
81 self.transport.send_email(to_email, subject, &body).await
82 }
83
84 /// Send a one-time login link
85 pub async fn send_login_link(
86 &self,
87 to_email: &str,
88 to_name: Option<&str>,
89 login_url: &str,
90 ) -> Result<()> {
91 let subject = "Your login link";
92 let body = format!(
93 r#"Hi{name},
94
95 Click the link below to log in to your account:
96
97 {url}
98
99 This link expires in 15 minutes and can only be used once.
100
101 If you didn't request this, you can ignore this email.
102
103 - Makenotwork"#,
104 name = crate::email::greeting(to_name),
105 url = login_url
106 );
107
108 self.transport.send_email(to_email, subject, &body).await
109 }
110
111 /// Send account deletion confirmation email
112 pub async fn send_deletion_confirmation(
113 &self,
114 to_email: &str,
115 to_name: Option<&str>,
116 delete_url: &str,
117 ) -> Result<()> {
118 let subject = "Confirm account deletion";
119 let body = format!(
120 r#"Hi{name},
121
122 You requested to delete your Makenotwork account.
123
124 IMPORTANT: This action is permanent and cannot be undone.
125
126 Clicking the link below will immediately and permanently delete:
127 - All your projects and items
128 - All uploaded content (audio, images)
129 - Your profile and account settings
130 - Your custom links
131
132 Purchases made by your fans will remain accessible to them.
133
134 To confirm deletion, click this link:
135
136 {url}
137
138 This link expires in 1 hour.
139
140 If you did not request this, do NOT click the link. Your account is safe.
141
142 - Makenotwork"#,
143 name = crate::email::greeting(to_name),
144 url = delete_url
145 );
146
147 self.transport.send_email(to_email, subject, &body).await
148 }
149
150 /// Send a new-device login notification
151 pub async fn send_new_login_notification(
152 &self,
153 to_email: &str,
154 to_name: Option<&str>,
155 device: Option<&str>,
156 ip: Option<&str>,
157 unsub_url: Option<&str>,
158 ) -> Result<()> {
159 let subject = "New sign-in to your account";
160 let device_line = device.unwrap_or("Unknown device");
161 let ip_line = ip.unwrap_or("Unknown");
162 let body = format!(
163 r#"Hi{name},
164
165 Your account was just signed in to from a new device.
166
167 Device: {device}
168 IP address: {ip}
169
170 If this was you, no action is needed. If you don't recognize this sign-in, go to your dashboard and revoke the session under Settings > Sessions.
171
172 - Makenotwork"#,
173 name = crate::email::greeting(to_name),
174 device = device_line,
175 ip = ip_line,
176 );
177
178 self.transport.send_email_with_unsub(to_email, subject, &body, unsub_url).await
179 }
180 }
181