Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Api/Client/Account/UpdateEmailRequest.php
10284 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Api\Client\Account;
4
5
use Pterodactyl\Models\User;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Hashing\Hasher;
8
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
9
use Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException;
10
11
class UpdateEmailRequest extends ClientApiRequest
12
{
13
/**
14
* @throws InvalidPasswordProvidedException
15
*/
16
public function authorize(): bool
17
{
18
if (!parent::authorize()) {
19
return false;
20
}
21
22
$hasher = Container::getInstance()->make(Hasher::class);
23
24
// Verify password matches when changing password or email.
25
if (!$hasher->check($this->input('password'), $this->user()->password)) {
26
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
27
}
28
29
return true;
30
}
31
32
public function rules(): array
33
{
34
$rules = User::getRulesForUpdate($this->user());
35
36
return ['email' => $rules['email']];
37
}
38
}
39
40