2018-06-11 22:56:57 -07:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Http\Requests\Api\Client\Account;
|
2018-06-11 22:56:57 -07:00
|
|
|
|
2025-09-24 13:34:19 +02:00
|
|
|
use App\Exceptions\Http\Base\InvalidPasswordProvidedException;
|
|
|
|
|
use App\Http\Requests\Api\Client\ClientApiRequest;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Models\User;
|
2021-08-15 17:37:12 -07:00
|
|
|
use Illuminate\Container\Container;
|
|
|
|
|
use Illuminate\Contracts\Hashing\Hasher;
|
2018-06-11 22:56:57 -07:00
|
|
|
|
|
|
|
|
class UpdateEmailRequest extends ClientApiRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
2025-09-08 13:12:33 -04:00
|
|
|
* @throws InvalidPasswordProvidedException
|
2018-06-11 22:56:57 -07:00
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
2021-01-23 12:33:34 -08:00
|
|
|
if (!parent::authorize()) {
|
2018-06-11 22:56:57 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 17:37:12 -07:00
|
|
|
$hasher = Container::getInstance()->make(Hasher::class);
|
|
|
|
|
|
2018-06-11 22:56:57 -07:00
|
|
|
// Verify password matches when changing password or email.
|
2021-08-15 17:37:12 -07:00
|
|
|
if (!$hasher->check($this->input('password'), $this->user()->password)) {
|
2018-07-15 11:44:18 -07:00
|
|
|
throw new InvalidPasswordProvidedException(trans('validation.internal.invalid_password'));
|
2018-06-11 22:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
2025-12-17 20:09:17 +01:00
|
|
|
return !$this->user()->is_managed_externally;
|
2018-06-11 22:56:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2019-09-04 22:26:28 -07:00
|
|
|
$rules = User::getRulesForUpdate($this->user());
|
2018-06-11 22:56:57 -07:00
|
|
|
|
2018-06-16 14:30:20 -07:00
|
|
|
return ['email' => $rules['email']];
|
2018-06-11 22:56:57 -07:00
|
|
|
}
|
|
|
|
|
}
|