Make email messages Markdown.

This commit is contained in:
James Cole
2022-03-29 12:45:48 +02:00
parent 9c19a08b17
commit 09bd0b572a
71 changed files with 747 additions and 555 deletions

View File

@@ -59,18 +59,16 @@ class APIEventHandler
$email = config('firefly.site_owner');
}
$ipAddress = Request::ip();
// see if user has alternative email address:
$pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');
if (null !== $pref) {
$email = (string)(is_array($pref->data) ? $email : $pref->data);
}
Log::debug(sprintf('Now in APIEventHandler::accessTokenCreated. Email is %s, IP is %s', $email, $ipAddress));
Log::debug(sprintf('Now in APIEventHandler::accessTokenCreated. Email is %s', $email));
try {
Log::debug('Trying to send message...');
Mail::to($email)->send(new AccessTokenCreatedMail($email, $ipAddress));
Mail::to($email)->send(new AccessTokenCreatedMail);
} catch (Exception $e) { // @phpstan-ignore-line
Log::debug('Send message failed! :(');

View File

@@ -52,7 +52,6 @@ class AdminEventHandler
// is user even admin?
if ($repository->hasRole($event->user, 'owner')) {
$email = $event->user->email;
$ipAddress = $event->ipAddress;
// if user is demo user, send to owner:
if ($event->user->hasRole('demo')) {
@@ -65,10 +64,10 @@ class AdminEventHandler
$email = $pref->data;
}
Log::debug(sprintf('Now in sendTestMessage event handler. Email is %s, IP is %s', $email, $ipAddress));
Log::debug(sprintf('Now in sendTestMessage event handler. Email is %s', $email));
try {
Log::debug('Trying to send message...');
Mail::to($email)->send(new AdminTestMail($email, $ipAddress));
Mail::to($email)->send(new AdminTestMail($email));
// Laravel cannot pretend this process failed during testing.
} catch (Exception $e) { // @phpstan-ignore-line

View File

@@ -58,23 +58,9 @@ class AutomationHandler
$repository = app(UserRepositoryInterface::class);
$user = $repository->find($event->userId);
if (null !== $user && 0 !== $event->groups->count()) {
$email = $user->email;
// see if user has alternative email address:
$pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');
if (null !== $pref) {
$email = $pref->data;
}
// if user is demo user, send to owner:
if ($user->hasRole('demo')) {
$email = config('firefly.site_owner');
}
try {
Log::debug('Trying to mail...');
Mail::to($user->email)->send(new ReportNewJournalsMail($email, '127.0.0.1', $event->groups));
Mail::to($user->email)->send(new ReportNewJournalsMail($event->groups));
} catch (Exception $e) { // @phpstan-ignore-line
Log::debug('Send message failed! :(');

View File

@@ -229,11 +229,10 @@ class UserEventHandler
$newEmail = $event->newEmail;
$oldEmail = $event->oldEmail;
$user = $event->user;
$ipAddress = $event->ipAddress;
$token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid');
$uri = route('profile.confirm-email-change', [$token->data]);
try {
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri));
} catch (Exception $e) { // @phpstan-ignore-line
Log::error($e->getMessage());
@@ -255,12 +254,11 @@ class UserEventHandler
$newEmail = $event->newEmail;
$oldEmail = $event->oldEmail;
$user = $event->user;
$ipAddress = $event->ipAddress;
$token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid');
$hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $oldEmail));
$uri = route('profile.undo-email-change', [$token->data, $hashed]);
try {
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri, $ipAddress));
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri));
} catch (Exception $e) { // @phpstan-ignore-line
Log::error($e->getMessage());