death-notifier/src/main/php/com/fwdekker/deathnotifier/mailer/ResetPasswordEmail.php

63 lines
1.6 KiB
PHP

<?php
namespace com\fwdekker\deathnotifier\mailer;
use com\fwdekker\deathnotifier\UserManager;
/**
* An email to help a user reset their password.
*/
class ResetPasswordEmail extends Email
{
/**
* A string identifying the type of email.
*/
public const TYPE = "reset-password";
/**
* @var string The token to reset the password with.
*/
public string $token;
/**
* Constructs an email to help a user reset their password.
*
* @param string $recipient the intended recipient of the email
* @param string $token the token to reset the password with
*/
public function __construct(string $recipient, string $token)
{
$this->type = self::TYPE;
$this->recipient = $recipient;
$this->token = $token;
$this->arg1 = $token;
}
public function getSubject(): string
{
return "Reset your password";
}
public function getBody(array $config): string
{
$base_path = $config["server"]["base_path"];
$verify_path =
"$base_path?action=reset-password&email=" . rawurlencode($this->recipient) . "&token=$this->token";
return
"You requested a password reset link for your Death Notifier account. " .
"You can choose a new password by clicking the link below. " .
"This link expires after " . UserManager::MINUTES_VALID_PASSWORD_RESET . " minutes." .
"\n" .
"Reset password: $verify_path" .
"\n\n" .
"If you did not request a new password, you can safely ignore this message." .
"\n\n" .
$base_path;
}
}