Files
firefly-iii/app/Handlers/Events/APIEventHandler.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2018-05-26 13:55:11 +02:00
<?php
/**
* 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
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-05-26 13:55:11 +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
*
* 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
* GNU Affero General Public License for more details.
2018-05-26 13:55:11 +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
2021-09-18 10:20:19 +02:00
use FireflyIII\Exceptions\FireflyException;
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;
use Log;
/**
* Class APIEventHandler
*/
class APIEventHandler
{
/**
2018-07-07 07:48:10 +02:00
* Respond to the creation of an access token.
*
2022-12-29 19:41:57 +01:00
* @param AccessTokenCreated $event
2018-05-26 13:55:11 +02:00
*
2021-09-18 10:20:19 +02:00
* @throws FireflyException
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
{
2022-09-24 07:03:03 +02:00
Log::debug(__METHOD__);
2018-05-26 13:55:11 +02:00
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
2022-12-29 19:41:57 +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) {
2022-10-30 14:24:19 +01:00
Notification::send($user, new NewAccessToken());
2018-05-26 13:55:11 +02:00
}
}
}