-
Notifications
You must be signed in to change notification settings - Fork 3
/
password-reset.ts
104 lines (83 loc) · 3.87 KB
/
password-reset.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* SudoSOS back-end API service.
* Copyright (C) 2024 Study association GEWIS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license
*/
/**
* This is the module page of the password-reset.
*
* @module internal/mailer
*/
import MailMessage, { Language, MailLanguageMap } from '../mail-message';
import MailContentBuilder from './mail-content-builder';
import { ResetTokenInfo } from '../../service/authentication-service';
interface WelcomeWithResetOptions {
email: string,
resetTokenInfo: ResetTokenInfo,
url?: string;
}
const passwordResetDutch = new MailContentBuilder<WelcomeWithResetOptions>({
getHTML: (context) => {
const link = context.url + '/passwordreset?token=' + context.resetTokenInfo.password + '&email=' + context.email;
return `
<p>Een wachtwoord reset voor dit email adres is aangevraagd. Om het proces te voltooien, gebruik de volgende link elk moment binnen de komende 60 minuten: </p>
<p><a href="${link}">Reset Link</a></p>
<p> Of plak de volgende link in je browser: ${link}</p>
<p>Als u geen wachtwoord reset heeft aangevraagd, kunt u deze e-mail veilig negeren en uw huidige inloggegevens gebruiken.</p>
<p>Tot op de borrel!</p>`;
},
getSubject: 'Wachtwoord resetten',
getTitle: 'Wachtwoordnotificatie',
getText: (context) => `
Een wachtwoord reset voor dit email adres is aangevraagd. Om het proces te voltooien, gebruik de volgende link elk moment binnen de komende 60 minuten:
${context.url + '/passwordreset?token=' + context.resetTokenInfo.password + '&email=' + context.email}
Als u geen wachtwoord reset heeft aangevraagd, kunt u deze e-mail veilig negeren en uw huidige inloggegevens gebruiken.
Tot op de borrel!`,
});
const passwordResetEnglish = new MailContentBuilder<WelcomeWithResetOptions>({
getHTML: (context) => {
const link = context.url + '/passwordreset?token=' + context.resetTokenInfo.password + '&email=' + context.email;
return `
<p>A password reset for this email address has been requested. To complete the process, use the following link any time within the next 60 minutes: </p>
<p><a href="${link}">Reset Link</a></p>
<p> Or paste the following in your browser: ${link}</p>
<p>If you have not requested a password reset, you can safely ignore this email and use your current login information.</p>
<p>See you on the borrel!</p>`;
},
getSubject: () => 'Password reset',
getTitle: () => 'Password notification',
getText: (context) => `
A password reset for this email address has been requested. To complete the process, use the following link any time within the next 60 minutes:
${context.url + '/passwordreset?token=' + context.resetTokenInfo.password + '&email=' + context.email}
If you have not requested a password reset, you can safely ignore this email and use your current login information.
See you on the borrel!`,
});
const mailContents: MailLanguageMap<WelcomeWithResetOptions> = {
[Language.DUTCH]: passwordResetDutch,
[Language.ENGLISH]: passwordResetEnglish,
};
export default class PasswordReset extends MailMessage<WelcomeWithResetOptions> {
public constructor(options: WelcomeWithResetOptions) {
const opt: WelcomeWithResetOptions = {
...options,
};
if (!options.url) {
opt.url = process.env.url;
}
super(opt, mailContents);
}
}