misc_pterodactyl-panel/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php

40 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Http\Requests\Api\Client\Account;
use Pterodactyl\Models\User;
use Illuminate\Container\Container;
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
use Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException;
class UpdateEmailRequest extends ClientApiRequest
{
/**
2022-12-15 01:04:16 +00:00
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException
*/
public function authorize(): bool
{
2021-01-23 20:33:34 +00:00
if (!parent::authorize()) {
return false;
}
$hasher = Container::getInstance()->make(Hasher::class);
// Verify password matches when changing password or email.
if (!$hasher->check($this->input('password'), $this->user()->password)) {
2018-07-15 18:44:18 +00:00
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
}
return true;
}
public function rules(): array
{
$rules = User::getRulesForUpdate($this->user());
return ['email' => $rules['email']];
}
}