38 lines
957 B
PHP
38 lines
957 B
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\IsEmailRule;
|
|
|
|
|
|
class SendPasswordResetAction extends Action
|
|
{
|
|
private readonly UserManager $user_manager;
|
|
|
|
|
|
public function __construct(UserManager $user_manager)
|
|
{
|
|
parent::__construct(
|
|
ActionMethod::POST,
|
|
"send-password-reset",
|
|
require_valid_csrf_token: true,
|
|
rule_lists: ["email" => [new IsEmailRule()]],
|
|
);
|
|
|
|
$this->user_manager = $user_manager;
|
|
}
|
|
|
|
|
|
function handle(): mixed
|
|
{
|
|
$response = $this->user_manager->send_password_reset($_POST["email"]);
|
|
if (!$response->satisfied)
|
|
throw new ActionException($response->payload["message"], $response->payload["target"]);
|
|
|
|
return $response->payload;
|
|
}
|
|
}
|