Files
panel-pelican-dev/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php
Lance Pioch 4ff5adc2a6 Monthly Shift: July 2026 (#2433)
Co-authored-by: Shift <shift@laravelshift.com>
2026-07-09 09:55:11 -04:00

37 lines
1.0 KiB
PHP

<?php
namespace App\Http\Requests\Api\Client\Account;
use App\Exceptions\Http\Base\InvalidPasswordProvidedException;
use App\Http\Requests\Api\Client\ClientApiRequest;
use App\Models\User;
use Illuminate\Container\Container;
use Illuminate\Contracts\Hashing\Hasher;
class UpdateEmailRequest extends ClientApiRequest
{
/**
* @throws InvalidPasswordProvidedException
*/
public function authorize(): bool
{
if (!parent::authorize()) {
return false;
}
$hasher = Container::getInstance()->make(Hasher::class);
// Verify password matches when changing password or email.
throw_unless($hasher->check($this->input('password'), $this->user()->password), new InvalidPasswordProvidedException(trans('validation.internal.invalid_password')));
return !$this->user()->is_managed_externally;
}
public function rules(): array
{
$rules = User::getRulesForUpdate($this->user());
return ['email' => $rules['email']];
}
}