2018-05-26 13:55:11 +02:00
|
|
|
<?php
|
2024-11-25 04:18:55 +01:00
|
|
|
|
2018-05-26 13:55:11 +02:00
|
|
|
/**
|
|
|
|
* APIEventHandler.php
|
2020-01-28 08:45:38 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-05-26 13:55:11 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-05-26 13:55:11 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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.
|
2018-05-26 13:55:11 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-05-26 13:55:11 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-05-26 13:55:11 +02:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* 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/>.
|
2018-05-26 13:55:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Handlers\Events;
|
2021-03-28 11:46:23 +02:00
|
|
|
|
2022-09-24 07:03:03 +02:00
|
|
|
use FireflyIII\Notifications\User\NewAccessToken;
|
2018-05-26 13:55:11 +02:00
|
|
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
2022-09-24 07:03:03 +02:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2018-05-26 13:55:11 +02:00
|
|
|
use Laravel\Passport\Events\AccessTokenCreated;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class APIEventHandler
|
|
|
|
*/
|
|
|
|
class APIEventHandler
|
|
|
|
{
|
|
|
|
/**
|
2018-07-07 07:48:10 +02:00
|
|
|
* Respond to the creation of an access token.
|
2018-05-26 13:55:11 +02:00
|
|
|
*/
|
2022-09-24 07:03:03 +02:00
|
|
|
public function accessTokenCreated(AccessTokenCreated $event): void
|
2018-05-26 13:55:11 +02:00
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(__METHOD__);
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2018-05-26 13:55:11 +02:00
|
|
|
/** @var UserRepositoryInterface $repository */
|
|
|
|
$repository = app(UserRepositoryInterface::class);
|
2024-12-22 08:43:12 +01:00
|
|
|
$user = $repository->find((int) $event->userId);
|
2021-04-07 07:28:43 +02:00
|
|
|
|
2022-09-24 07:03:03 +02:00
|
|
|
if (null !== $user) {
|
2023-06-11 16:12:13 +02:00
|
|
|
try {
|
|
|
|
Notification::send($user, new NewAccessToken());
|
2025-01-04 19:43:58 +01:00
|
|
|
} catch (\Exception $e) {
|
2023-06-11 16:12:13 +02:00
|
|
|
$message = $e->getMessage();
|
|
|
|
if (str_contains($message, 'Bcc')) {
|
2023-10-29 06:31:13 +01:00
|
|
|
app('log')->warning('[Bcc] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-11 16:12:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (str_contains($message, 'RFC 2822')) {
|
2023-10-29 06:31:13 +01:00
|
|
|
app('log')->warning('[RFC] Could not send notification. Please validate your email settings, use the .env.example file as a guide.');
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2023-06-11 16:12:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2023-10-29 06:32:00 +01:00
|
|
|
app('log')->error($e->getMessage());
|
|
|
|
app('log')->error($e->getTraceAsString());
|
2023-06-11 16:12:13 +02:00
|
|
|
}
|
2018-05-26 13:55:11 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-22 20:32:02 +02:00
|
|
|
}
|