2023-03-24 13:54:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Actions\Fortify;
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2024-10-28 20:57:00 +00:00
|
|
|
use Illuminate\Validation\Rules\Password;
|
2026-03-10 00:42:36 +00:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2023-03-24 13:54:17 +00:00
|
|
|
use Laravel\Fortify\Contracts\UpdatesUserPasswords;
|
|
|
|
|
|
|
|
|
|
class UpdateUserPassword implements UpdatesUserPasswords
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Validate and update the user's password.
|
|
|
|
|
*
|
2024-06-10 20:43:34 +00:00
|
|
|
* @param array<string, string> $input
|
2023-03-24 13:54:17 +00:00
|
|
|
*/
|
|
|
|
|
public function update(User $user, array $input): void
|
|
|
|
|
{
|
2026-03-10 00:42:36 +00:00
|
|
|
$settings = instanceSettings();
|
2026-03-10 00:17:33 +00:00
|
|
|
// Prevent OAuth-only users from updating passwords
|
2026-03-10 00:42:36 +00:00
|
|
|
if ($settings->oauth_only || $user->oauth_only) {
|
|
|
|
|
throw ValidationException::withMessages([
|
|
|
|
|
'current_password' => __('Password update is disabled for OAuth-only accounts.'),
|
|
|
|
|
]);
|
2026-03-10 00:17:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-24 13:54:17 +00:00
|
|
|
Validator::make($input, [
|
|
|
|
|
'current_password' => ['required', 'string', 'current_password:web'],
|
2024-10-28 20:57:00 +00:00
|
|
|
'password' => ['required', Password::defaults(), 'confirmed'],
|
2023-03-24 13:54:17 +00:00
|
|
|
], [
|
|
|
|
|
'current_password.current_password' => __('The provided password does not match your current password.'),
|
|
|
|
|
])->validateWithBag('updatePassword');
|
|
|
|
|
|
|
|
|
|
$user->forceFill([
|
|
|
|
|
'password' => Hash::make($input['password']),
|
|
|
|
|
])->save();
|
|
|
|
|
}
|
|
|
|
|
}
|