Files
UNIT3D/app/Actions/Fortify/ResetUserPassword.php
Roardom 48adfce1af fix: group cache
Laravel returns numeric strings when an int is saved to cache, which breaks a lot of the logic here. Fixed by removing cache everywhere except rss and middleware, and in those two spots, caching the whole group and not just the id of the group.
2025-07-19 11:59:00 +00:00

66 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Actions\Fortify;
use App\Models\Group;
use App\Models\User;
use App\Services\Unit3dAnnounce;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use Laravel\Fortify\Contracts\ResetsUserPasswords;
class ResetUserPassword implements ResetsUserPasswords
{
use PasswordValidationRules;
/**
* Validate and reset the user's forgotten password.
*
* @param array<string, string> $input
* @throws ValidationException
*/
public function reset(User $user, array $input): void
{
Validator::make($input, [
'password' => $this->passwordRules(),
])->validate();
$user->forceFill([
'password' => Hash::make($input['password']),
]);
$validatingGroupId = Group::query()->where('slug', '=', 'validating')->soleValue('id');
if ($user->group_id === $validatingGroupId) {
$user->group_id = Group::query()->where('slug', '=', 'user')->soleValue('id');
cache()->forget('user:'.$user->passkey);
Unit3dAnnounce::addUser($user);
}
if (!$user->hasVerifiedEmail()) {
$user->markEmailAsVerified();
}
$user->save();
$user->passwordResetHistories()->create();
}
}