refactor: move to new mailer
This commit is contained in:
parent
d842c14240
commit
0f4c8b2051
@ -131,7 +131,7 @@ export class RunnerSelfServiceController {
|
|||||||
const token = JwtCreator.createSelfService(runner);
|
const token = JwtCreator.createSelfService(runner);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Mailer.sendSelfserviceForgottenMail(runner.email, token, locale)
|
await Mailer.sendSelfserviceForgottenMail(runner.email, runner.id, runner.firstname, runner.lastname, token, locale)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new MailSendingError();
|
throw new MailSendingError();
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ export class RunnerSelfServiceController {
|
|||||||
response.token = JwtCreator.createSelfService(runner);
|
response.token = JwtCreator.createSelfService(runner);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Mailer.sendSelfserviceWelcomeMail(runner.email, response.token, locale)
|
await Mailer.sendSelfserviceWelcomeMail(runner.email, runner.id, runner.firstname, runner.lastname, response.token, locale)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new MailSendingError();
|
throw new MailSendingError();
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ export class RunnerSelfServiceController {
|
|||||||
response.token = JwtCreator.createSelfService(runner);
|
response.token = JwtCreator.createSelfService(runner);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Mailer.sendSelfserviceWelcomeMail(runner.email, response.token, locale)
|
await Mailer.sendSelfserviceWelcomeMail(runner.email, runner.id, runner.firstname, runner.lastname, response.token, locale)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new MailSendingError();
|
throw new MailSendingError();
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,19 @@ export class Mailer {
|
|||||||
*/
|
*/
|
||||||
public static async sendResetMail(to_address: string, token: string, locale: string = "en") {
|
public static async sendResetMail(to_address: string, token: string, locale: string = "en") {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${Mailer.base}/reset?locale=${locale}&key=${Mailer.key}`, {
|
await axios.request({
|
||||||
address: to_address,
|
method: 'POST',
|
||||||
resetKey: token
|
url: `${Mailer.base}/api/v1/email`,
|
||||||
|
headers: {
|
||||||
|
authorization: `Bearer ${Mailer.key}`,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
to: to_address,
|
||||||
|
templateName: 'password-reset',
|
||||||
|
language: locale,
|
||||||
|
data: { token: token }
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (Mailer.testing) { return true; }
|
if (Mailer.testing) { return true; }
|
||||||
@ -33,11 +43,25 @@ export class Mailer {
|
|||||||
* @param to_address The address the mail will be sent to. Should always get pulled from a runner object.
|
* @param to_address The address the mail will be sent to. Should always get pulled from a runner object.
|
||||||
* @param token The requested selfservice token - will be combined with the app_url to generate a selfservice profile link.
|
* @param token The requested selfservice token - will be combined with the app_url to generate a selfservice profile link.
|
||||||
*/
|
*/
|
||||||
public static async sendSelfserviceWelcomeMail(to_address: string, token: string, locale: string = "en") {
|
public static async sendSelfserviceWelcomeMail(to_address: string, runner_id: number, firstname: string, lastname: string, token: string, locale: string = "en") {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${Mailer.base}/registration?locale=${locale}&key=${Mailer.key}`, {
|
await axios.request({
|
||||||
address: to_address,
|
method: 'POST',
|
||||||
selfserviceToken: token
|
url: `${Mailer.base}/api/v1/email`,
|
||||||
|
headers: {
|
||||||
|
authorization: `Bearer ${Mailer.key}`,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
to: to_address,
|
||||||
|
templateName: 'welcome',
|
||||||
|
language: locale,
|
||||||
|
data: {
|
||||||
|
name: `${firstname} ${lastname}`,
|
||||||
|
barcode_content: `${runner_id}`,
|
||||||
|
link: 'https://portal.lauf-fuer-kaya.de/profile/' + token
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (Mailer.testing) { return true; }
|
if (Mailer.testing) { return true; }
|
||||||
@ -50,11 +74,25 @@ export class Mailer {
|
|||||||
* @param to_address The address the mail will be sent to. Should always get pulled from a runner object.
|
* @param to_address The address the mail will be sent to. Should always get pulled from a runner object.
|
||||||
* @param token The requested selfservice token - will be combined with the app_url to generate a selfservice profile link.
|
* @param token The requested selfservice token - will be combined with the app_url to generate a selfservice profile link.
|
||||||
*/
|
*/
|
||||||
public static async sendSelfserviceForgottenMail(to_address: string, token: string, locale: string = "en") {
|
public static async sendSelfserviceForgottenMail(to_address: string, runner_id: number, firstname: string, lastname: string, token: string, locale: string = "en") {
|
||||||
try {
|
try {
|
||||||
await axios.post(`${Mailer.base}/registration_forgot?locale=${locale}&key=${Mailer.key}`, {
|
await axios.request({
|
||||||
address: to_address,
|
method: 'POST',
|
||||||
selfserviceToken: token
|
url: `${Mailer.base}/api/v1/email`,
|
||||||
|
headers: {
|
||||||
|
authorization: `Bearer ${Mailer.key}`,
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
to: to_address,
|
||||||
|
templateName: 'welcome',
|
||||||
|
language: locale,
|
||||||
|
data: {
|
||||||
|
name: `${firstname} ${lastname}`,
|
||||||
|
barcode_content: `${runner_id}`,
|
||||||
|
link: 'https://portal.lauf-fuer-kaya.de/profile/' + token
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (Mailer.testing) { return true; }
|
if (Mailer.testing) { return true; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user