mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-24 20:55:31 +00:00
Merge branch 'develop' into 5.8-dev
This commit is contained in:
@@ -26,7 +26,10 @@ namespace FireflyIII\Handlers\Events;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Mail\AccessTokenCreatedMail;
|
||||
use FireflyIII\Notifications\Admin\TestNotification;
|
||||
use FireflyIII\Notifications\User\NewAccessToken;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Laravel\Passport\Events\AccessTokenCreated;
|
||||
use Log;
|
||||
use Mail;
|
||||
@@ -42,45 +45,18 @@ class APIEventHandler
|
||||
*
|
||||
* @param AccessTokenCreated $event
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function accessTokenCreated(AccessTokenCreated $event): bool
|
||||
public function accessTokenCreated(AccessTokenCreated $event): void
|
||||
{
|
||||
Log::debug(__METHOD__);
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$user = $repository->find((int) $event->userId);
|
||||
|
||||
if (null !== $user) {
|
||||
$email = $user->email;
|
||||
|
||||
// if user is demo user, send to owner:
|
||||
if ($user->hasRole('demo')) {
|
||||
$email = config('firefly.site_owner');
|
||||
}
|
||||
|
||||
// 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', $email));
|
||||
try {
|
||||
Log::debug('Trying to send message...');
|
||||
Mail::to($email)->send(new AccessTokenCreatedMail);
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::debug('Send message failed! :(');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
Session::flash('error', 'Possible email error: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
Log::debug('If no error above this line, message was sent.');
|
||||
Notification::send($user, new NewAccessToken);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,17 +45,15 @@ class AdminEventHandler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendTestMessage(AdminRequestedTestMessage $event): bool
|
||||
public function sendTestMessage(AdminRequestedTestMessage $event): void
|
||||
{
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
// do some validation.
|
||||
|
||||
if (!$repository->hasRole($event->user, 'owner')) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::send($event->user, new TestNotification($event->user->email));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,12 @@ use Exception;
|
||||
use FireflyIII\Events\RequestedReportOnJournals;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Mail\ReportNewJournalsMail;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Notifications\User\NewAccessToken;
|
||||
use FireflyIII\Notifications\User\TransactionCreation;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Log;
|
||||
use Mail;
|
||||
|
||||
@@ -41,36 +46,31 @@ class AutomationHandler
|
||||
* Respond to the creation of X journals.
|
||||
*
|
||||
* @param RequestedReportOnJournals $event
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated
|
||||
*/
|
||||
public function reportJournals(RequestedReportOnJournals $event): bool
|
||||
public function reportJournals(RequestedReportOnJournals $event): void
|
||||
{
|
||||
Log::debug('In reportJournals.');
|
||||
$sendReport = config('firefly.send_report_journals');
|
||||
|
||||
if (false === $sendReport) {
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('In reportJournals.');
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$user = $repository->find($event->userId);
|
||||
if (null !== $user && 0 !== $event->groups->count()) {
|
||||
try {
|
||||
Log::debug('Trying to mail...');
|
||||
Mail::to($user->email)->send(new ReportNewJournalsMail($event->groups));
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::debug('Send message failed! :(');
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
}
|
||||
|
||||
Log::debug('Done!');
|
||||
if (null === $user || 0 === $event->groups->count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return true;
|
||||
// transform groups into array:
|
||||
/** @var TransactionGroupTransformer $transformer */
|
||||
$transformer = app(TransactionGroupTransformer::class);
|
||||
$groups = [];
|
||||
/** @var TransactionGroup $group */
|
||||
foreach ($event->groups as $group) {
|
||||
$groups[] = $transformer->transformObject($group);
|
||||
}
|
||||
|
||||
Notification::send($user, new TransactionCreation($groups));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,6 @@ class BillEventHandler
|
||||
/**
|
||||
* @param WarnUserAboutBill $event
|
||||
* @return void
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function warnAboutBill(WarnUserAboutBill $event): void
|
||||
{
|
||||
|
||||
@@ -33,16 +33,18 @@ use FireflyIII\Events\RequestedNewPassword;
|
||||
use FireflyIII\Events\UserChangedEmail;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Mail\ConfirmEmailChangeMail;
|
||||
use FireflyIII\Mail\NewIPAddressWarningMail;
|
||||
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
|
||||
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
|
||||
use FireflyIII\Mail\UndoEmailChangeMail;
|
||||
use FireflyIII\Models\GroupMembership;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\Notifications\User\UserLogin;
|
||||
use FireflyIII\Notifications\User\UserNewPassword;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Auth\Events\Login;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Log;
|
||||
use Mail;
|
||||
|
||||
@@ -62,7 +64,7 @@ class UserEventHandler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function attachUserRole(RegisteredUser $event): bool
|
||||
public function attachUserRole(RegisteredUser $event): void
|
||||
{
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
@@ -72,19 +74,16 @@ class UserEventHandler
|
||||
Log::debug('User count is one, attach role.');
|
||||
$repository->attachRole($event->user, 'owner');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RegisteredUser $event
|
||||
* @return bool
|
||||
*/
|
||||
public function createExchangeRates(RegisteredUser $event): bool {
|
||||
public function createExchangeRates(RegisteredUser $event): void
|
||||
{
|
||||
$seeder = new ExchangeRateSeeder;
|
||||
$seeder->run();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +93,7 @@ class UserEventHandler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkSingleUserIsAdmin(Login $event): bool
|
||||
public function checkSingleUserIsAdmin(Login $event): void
|
||||
{
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
@@ -117,8 +116,6 @@ class UserEventHandler
|
||||
// give user the role
|
||||
$repository->attachRole($user, 'owner');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +124,7 @@ class UserEventHandler
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function createGroupMembership(RegisteredUser $event): bool
|
||||
public function createGroupMembership(RegisteredUser $event): void
|
||||
{
|
||||
$user = $event->user;
|
||||
$groupExists = true;
|
||||
@@ -160,8 +157,6 @@ class UserEventHandler
|
||||
);
|
||||
$user->user_group_id = $group->id;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +167,7 @@ class UserEventHandler
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function demoUserBackToEnglish(Login $event): bool
|
||||
public function demoUserBackToEnglish(Login $event): void
|
||||
{
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
@@ -185,15 +180,12 @@ class UserEventHandler
|
||||
app('preferences')->setForUser($user, 'locale', 'equal');
|
||||
app('preferences')->mark();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DetectedNewIPAddress $event
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function notifyNewIPAddress(DetectedNewIPAddress $event): void
|
||||
{
|
||||
@@ -207,21 +199,10 @@ class UserEventHandler
|
||||
|
||||
$list = app('preferences')->getForUser($user, 'login_ip_history', [])->data;
|
||||
|
||||
// see if user has alternative email address:
|
||||
$pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');
|
||||
if (null !== $pref) {
|
||||
$email = $pref->data;
|
||||
}
|
||||
|
||||
/** @var array $entry */
|
||||
foreach ($list as $index => $entry) {
|
||||
if (false === $entry['notified']) {
|
||||
try {
|
||||
Mail::to($email)->send(new NewIPAddressWarningMail($ipAddress));
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
Notification::send($user, new UserLogin($ipAddress));
|
||||
}
|
||||
$list[$index]['notified'] = true;
|
||||
}
|
||||
@@ -230,41 +211,38 @@ class UserEventHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Send email to confirm email change.
|
||||
* Send email to confirm email change. Will not be made into a notification, because
|
||||
* this requires some custom fields from the user and not just the "user" object.
|
||||
*
|
||||
* @param UserChangedEmail $event
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function sendEmailChangeConfirmMail(UserChangedEmail $event): bool
|
||||
public function sendEmailChangeConfirmMail(UserChangedEmail $event): void
|
||||
{
|
||||
$newEmail = $event->newEmail;
|
||||
$oldEmail = $event->oldEmail;
|
||||
$user = $event->user;
|
||||
$token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid');
|
||||
$url = route('profile.confirm-email-change', [$token->data]);
|
||||
|
||||
try {
|
||||
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $url));
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send email to be able to undo email change.
|
||||
* Send email to be able to undo email change. Will not be made into a notification, because
|
||||
* this requires some custom fields from the user and not just the "user" object.
|
||||
*
|
||||
* @param UserChangedEmail $event
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function sendEmailChangeUndoMail(UserChangedEmail $event): bool
|
||||
public function sendEmailChangeUndoMail(UserChangedEmail $event): void
|
||||
{
|
||||
$newEmail = $event->newEmail;
|
||||
$oldEmail = $event->oldEmail;
|
||||
@@ -278,53 +256,36 @@ class UserEventHandler
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a new password to the user.
|
||||
* @deprecated
|
||||
* @param RequestedNewPassword $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendNewPassword(RequestedNewPassword $event): bool
|
||||
public function sendNewPassword(RequestedNewPassword $event): void
|
||||
{
|
||||
$email = $event->user->email;
|
||||
$ipAddress = $event->ipAddress;
|
||||
$token = $event->token;
|
||||
|
||||
$url = route('password.reset', [$token]);
|
||||
|
||||
// send email.
|
||||
try {
|
||||
Mail::to($email)->send(new RequestedNewPasswordMail($url, $ipAddress));
|
||||
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
Notification::send($event->user, new UserNewPassword(route('password.reset', [$event->token])));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will send the user a registration mail, welcoming him or her to Firefly III.
|
||||
* This message is only sent when the configuration of Firefly III says so.
|
||||
*
|
||||
* TODO this is an admin setting not a variable. Fix that first.
|
||||
*
|
||||
* @param RegisteredUser $event
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated
|
||||
* @throws FireflyException
|
||||
* @deprecated
|
||||
*/
|
||||
public function sendRegistrationMail(RegisteredUser $event): bool
|
||||
public function sendRegistrationMail(RegisteredUser $event): void
|
||||
{
|
||||
$sendMail = config('firefly.send_registration_mail');
|
||||
if ($sendMail) {
|
||||
// get the email address
|
||||
$email = $event->user->email;
|
||||
$url = route('index');
|
||||
$email = $event->user->email;
|
||||
$url = route('index');
|
||||
|
||||
// see if user has alternative email address:
|
||||
$pref = app('preferences')->getForUser($event->user, 'remote_guard_alt_email');
|
||||
@@ -341,8 +302,6 @@ class UserEventHandler
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,7 +314,7 @@ class UserEventHandler
|
||||
$user = $event->user;
|
||||
/** @var array $preference */
|
||||
|
||||
if($user->hasRole('demo')) {
|
||||
if ($user->hasRole('demo')) {
|
||||
Log::debug('Do not log demo user logins');
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user