2020-06-11 06:55:13 +02:00
|
|
|
<?php
|
2020-06-30 19:05:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoteUserProvider.php
|
|
|
|
* Copyright (c) 2020 james@firefly-iii.org
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-06-11 06:55:13 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Support\Authentication;
|
2021-09-18 10:26:12 +02:00
|
|
|
|
2023-03-26 19:19:10 +02:00
|
|
|
use FireflyIII\Console\Commands\Integrity\CreateGroupMemberships;
|
2020-06-11 06:55:13 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2022-07-16 17:15:44 +02:00
|
|
|
use FireflyIII\Models\Role;
|
2020-06-11 06:55:13 +02:00
|
|
|
use FireflyIII\User;
|
|
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
|
|
use Illuminate\Contracts\Auth\UserProvider;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RemoteUserProvider
|
|
|
|
*/
|
|
|
|
class RemoteUserProvider implements UserProvider
|
|
|
|
{
|
2023-12-21 05:15:46 +01:00
|
|
|
/**
|
|
|
|
* @throws FireflyException
|
2023-12-21 05:46:05 +01:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
2023-12-21 05:15:46 +01:00
|
|
|
*/
|
|
|
|
public function retrieveByCredentials(array $credentials): null|Authenticatable
|
2020-06-11 06:55:13 +02:00
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2020-06-11 06:55:13 +02:00
|
|
|
throw new FireflyException(sprintf('Did not implement %s', __METHOD__));
|
|
|
|
}
|
|
|
|
|
2023-12-21 05:15:46 +01:00
|
|
|
/**
|
|
|
|
* @param mixed $identifier
|
|
|
|
*
|
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
2020-06-11 06:55:13 +02:00
|
|
|
public function retrieveById($identifier): User
|
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now at %s(%s)', __METHOD__, $identifier));
|
2020-06-11 06:55:13 +02:00
|
|
|
$user = User::where('email', $identifier)->first();
|
|
|
|
if (null === $user) {
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('User with email "%s" not found. Will be created.', $identifier));
|
2020-06-11 06:55:13 +02:00
|
|
|
$user = User::create(
|
|
|
|
[
|
2022-03-29 15:00:29 +02:00
|
|
|
'blocked' => false,
|
2020-06-11 06:55:13 +02:00
|
|
|
'blocked_code' => null,
|
2022-03-29 15:00:29 +02:00
|
|
|
'email' => $identifier,
|
2023-12-20 19:35:52 +01:00
|
|
|
'password' => bcrypt(\Str::random(64)),
|
2020-06-11 06:55:13 +02:00
|
|
|
]
|
|
|
|
);
|
2022-07-16 17:15:44 +02:00
|
|
|
// if this is the first user, give them admin as well.
|
2022-10-30 14:24:37 +01:00
|
|
|
if (1 === User::count()) {
|
2022-07-16 17:15:44 +02:00
|
|
|
$roleObject = Role::where('name', 'owner')->first();
|
|
|
|
$user->roles()->attach($roleObject);
|
|
|
|
}
|
2023-03-26 19:19:10 +02:00
|
|
|
// make sure the user gets an administration as well.
|
|
|
|
CreateGroupMemberships::createGroupMembership($user);
|
2020-06-11 06:55:13 +02:00
|
|
|
}
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Going to return user #%d (%s)', $user->id, $user->email));
|
2020-06-11 06:55:13 +02:00
|
|
|
|
|
|
|
return $user;
|
|
|
|
}
|
|
|
|
|
2023-12-21 05:15:46 +01:00
|
|
|
/**
|
|
|
|
* @param mixed $identifier
|
|
|
|
* @param mixed $token
|
|
|
|
*
|
|
|
|
* @throws FireflyException
|
2023-12-21 05:46:05 +01:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
2023-12-21 05:15:46 +01:00
|
|
|
*/
|
|
|
|
public function retrieveByToken($identifier, $token): null|Authenticatable
|
2020-06-11 06:55:13 +02:00
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2021-05-28 23:13:38 +02:00
|
|
|
throw new FireflyException(sprintf('A) Did not implement %s', __METHOD__));
|
2020-06-11 06:55:13 +02:00
|
|
|
}
|
|
|
|
|
2023-12-21 05:46:05 +01:00
|
|
|
/**
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
|
|
*
|
|
|
|
* @param mixed $token
|
|
|
|
*
|
|
|
|
* @throws FireflyException
|
|
|
|
*/
|
2023-12-21 05:07:26 +01:00
|
|
|
public function updateRememberToken(Authenticatable $user, $token): void
|
2020-06-11 06:55:13 +02:00
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2021-05-28 23:13:38 +02:00
|
|
|
throw new FireflyException(sprintf('B) Did not implement %s', __METHOD__));
|
2020-06-11 06:55:13 +02:00
|
|
|
}
|
|
|
|
|
2023-12-21 05:15:46 +01:00
|
|
|
/**
|
|
|
|
* @throws FireflyException
|
2023-12-21 05:46:05 +01:00
|
|
|
*
|
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
2023-12-21 05:15:46 +01:00
|
|
|
*/
|
|
|
|
public function validateCredentials(Authenticatable $user, array $credentials): bool
|
2020-06-11 06:55:13 +02:00
|
|
|
{
|
2023-10-29 06:33:43 +01:00
|
|
|
app('log')->debug(sprintf('Now at %s', __METHOD__));
|
2023-12-20 19:35:52 +01:00
|
|
|
|
2021-05-28 23:13:38 +02:00
|
|
|
throw new FireflyException(sprintf('C) Did not implement %s', __METHOD__));
|
2020-06-11 06:55:13 +02:00
|
|
|
}
|
|
|
|
}
|