40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace com\fwdekker\deathnotifier\user;
|
|
|
|
use com\fwdekker\deathnotifier\Action;
|
|
use com\fwdekker\deathnotifier\ActionException;
|
|
use com\fwdekker\deathnotifier\ActionMethod;
|
|
use com\fwdekker\deathnotifier\validator\HasLengthRule;
|
|
|
|
|
|
class ResetPasswordAction extends Action
|
|
{
|
|
private readonly UserManager $user_manager;
|
|
|
|
|
|
public function __construct(UserManager $user_manager)
|
|
{
|
|
parent::__construct(
|
|
ActionMethod::POST,
|
|
"reset-password",
|
|
require_valid_csrf_token: true,
|
|
rule_lists: [
|
|
"password" => [new HasLengthRule(UserManager::MIN_PASSWORD_LENGTH, UserManager::MAX_PASSWORD_LENGTH)],
|
|
],
|
|
);
|
|
|
|
$this->user_manager = $user_manager;
|
|
}
|
|
|
|
|
|
function handle(): mixed
|
|
{
|
|
$response = $this->user_manager->reset_password($_POST["email"], $_POST["reset_token"], $_POST["password"]);
|
|
if (!$response->satisfied)
|
|
throw new ActionException($response->payload["message"], $response->payload["target"]);
|
|
|
|
return $response->payload;
|
|
}
|
|
}
|