Extract System emails from enotify

- Removed every SYSTEM_EMAIL occurrence in enotify
- Introduced a "SystemMailBuilder" for build system emails
- Replaced every SYSTEM_EMAIL usage in the classes with calling this builder
- Added tests for this new Builder
- Split the email templates between "base" template for email and concrete usages for different use cases
This commit is contained in:
nupplaPhil 2020-02-01 20:08:54 +01:00
parent 74490d6594
commit 3291728059
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
18 changed files with 647 additions and 118 deletions

View file

@ -64,17 +64,14 @@ function lostpass_post(App $a)
Site Location: %2$s
Login Name: %3$s', $resetlink, DI::baseUrl(), $user['nickname']));
notification([
'type' => SYSTEM_EMAIL,
'language' => $user['language'],
'to_name' => $user['username'],
'to_email' => $user['email'],
'uid' => $user['uid'],
'subject' => DI::l10n()->t('Password reset requested at %s', $sitename),
'preamble' => $preamble,
'body' => $body
]);
$email = DI::emailer()
->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
->withMessage(DI::l10n()->t('Password reset requested at %s', $sitename), $preamble, $body)
->forUser($user['uid'] ?? 0)
->withRecipient($user['to_email'])
->build();
DI::emailer()->send($email);
DI::baseUrl()->redirect();
}
@ -159,16 +156,13 @@ function lostpass_generate_password($user)
You may change that password from your account settings page after logging in.
', DI::baseUrl(), $user['nickname'], $new_password));
notification([
'type' => SYSTEM_EMAIL,
'language' => $user['language'],
'to_name' => $user['username'],
'to_email' => $user['email'],
'uid' => $user['uid'],
'subject' => DI::l10n()->t('Your password has been changed at %s', $sitename),
'preamble' => $preamble,
'body' => $body
]);
$email = DI::emailer()
->newSystemMail((!empty($user['language'])) ? DI::l10n()->withLang($user['language']) : DI::l10n())
->withMessage(DI::l10n()->t('Your password has been changed at %s', $sitename), $preamble, $body)
->forUser($user['uid'] ?? 0)
->withRecipient($user['to_email'])
->build();
DI::emailer()->send($email);
}
return $o;