Add password reset message

This commit is contained in:
Jay Trees 2022-03-01 10:59:06 +01:00
parent 062232a71d
commit b176ed1dc6
4 changed files with 14 additions and 13 deletions

View file

@ -91,6 +91,7 @@ class Page
* Non-Static * Non-Static
*/ */
public string $language = 'en'; public string $language = 'en';
public array $messages = array();
/** /**
* __construct * __construct
@ -482,11 +483,11 @@ class Page
<?php <?php
} }
public function messages(array $messages): string public function messages(): string
{ {
$html = ''; $html = '';
foreach ($messages as $message) { foreach ($this->messages as $message) {
$html .= $message; $html .= $message;
} }

View file

@ -55,6 +55,8 @@ if (isset($_POST['reset'], $_POST['email'])) {
$emailReset = new Email($_POST['email'], 'Password reset link', $mjml); $emailReset = new Email($_POST['email'], 'Password reset link', $mjml);
$emailReset->send(); $emailReset->send();
$page->messages[] = Page::info('If we can find a match for this email address, a password reset link will be sent to it.', 'Info');
} }
} }

View file

@ -8,8 +8,7 @@
use wishthis\Page; use wishthis\Page;
$page = new page(__FILE__, 'Register'); $page = new page(__FILE__, 'Register');
$messages = array();
if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
$users = $database->query('SELECT * FROM `users`;')->fetchAll(); $users = $database->query('SELECT * FROM `users`;')->fetchAll();
@ -43,7 +42,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
} }
if (in_array($planet, $not_planets)) { if (in_array($planet, $not_planets)) {
$messages[] = Page::warning('<strong>' . $planetName . '</strong> is not a planet but I\'ll let it slide, since only a human would make this kind of mistake.', 'Invalid planet'); $page->messages[] = Page::warning('<strong>' . $planetName . '</strong> is not a planet but I\'ll let it slide, since only a human would make this kind of mistake.', 'Invalid planet');
} }
if ($isHuman) { if ($isHuman) {
@ -61,7 +60,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
;'); ;');
} else { } else {
if (in_array($_POST['email'], $emails)) { if (in_array($_POST['email'], $emails)) {
$messages[] = Page::error('An account with this email address already exists.', 'Invalid email address'); $page->messages[] = Page::error('An account with this email address already exists.', 'Invalid email address');
} else { } else {
$database->query('INSERT INTO `users` $database->query('INSERT INTO `users`
( (
@ -73,11 +72,11 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
) )
;'); ;');
$messages[] = Page::success('Your account was successfully created.', 'Success'); $page->messages[] = Page::success('Your account was successfully created.', 'Success');
} }
} }
} else { } else {
$messages[] = Page::error('<strong>' . $planetName . '</strong> is not a planet in our solar system. Read this for more information: <a href="https://www.space.com/16080-solar-system-planets.html" target="_blank">Solar system planets: Order of the 8 (or 9) planets</a>', 'Invalid planet'); $page->messages[] = Page::error('<strong>' . $planetName . '</strong> is not a planet in our solar system. Read this for more information: <a href="https://www.space.com/16080-solar-system-planets.html" target="_blank">Solar system planets: Order of the 8 (or 9) planets</a>', 'Invalid planet');
} }
} }
@ -89,7 +88,7 @@ $page->navigation();
<div class="ui container"> <div class="ui container">
<h1 class="ui header"><?= $page->title ?></h1> <h1 class="ui header"><?= $page->title ?></h1>
<?= $page->messages($messages) ?> <?= $page->messages() ?>
<div class="ui segment"> <div class="ui segment">
<form class="ui form" method="post"> <form class="ui form" method="post">

View file

@ -8,7 +8,7 @@
use wishthis\{Page, Wish}; use wishthis\{Page, Wish};
$messages = array(); $page = new page(__FILE__, $wish->title);
if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) { if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) {
$database $database
@ -18,7 +18,7 @@ if ('POST' === $_SERVER['REQUEST_METHOD'] && count($_POST) >= 0) {
`url` = "' . trim($_POST['wish_url']) . '" `url` = "' . trim($_POST['wish_url']) . '"
WHERE `id` = ' . trim($_POST['wish_id']) . ';'); WHERE `id` = ' . trim($_POST['wish_id']) . ';');
$messages[] = Page::success('Wish successfully updated.', 'Success'); $page->messages[] = Page::success('Wish successfully updated.', 'Success');
} }
$userIsAuthenticated = false; $userIsAuthenticated = false;
@ -41,7 +41,6 @@ if (!$userIsAuthenticated) {
die(); die();
} }
$page = new page(__FILE__, $wish->title);
$page->header(); $page->header();
$page->bodyStart(); $page->bodyStart();
$page->navigation(); $page->navigation();
@ -53,7 +52,7 @@ $referer = '/?page=wishlists&wishlist=' . $wish->wishlist;
<div class="ui container"> <div class="ui container">
<h1 class="ui header"><?= $page->title ?></h1> <h1 class="ui header"><?= $page->title ?></h1>
<?= $page->messages($messages) ?> <?= $page->messages() ?>
<div class="ui segment"> <div class="ui segment">
<form class="ui form wish" method="POST"> <form class="ui form wish" method="POST">