Files
breadcrumb-the-shire/pages/auth/reset().php
2026-02-04 23:31:53 +01:00

41 lines
1.2 KiB
PHP

<?php
use MintyPHP\Buffer;
use MintyPHP\Support\Flash;
use MintyPHP\Session;
use MintyPHP\Router;
use MintyPHP\Http\Request;
use MintyPHP\I18n;
use MintyPHP\Service\PasswordResetService;
use MintyPHP\Service\UserService;
$errors = [];
$password = (string) ($_POST['password'] ?? '');
$password2 = (string) ($_POST['password2'] ?? '');
$resetId = (int) ($_SESSION['password_reset_id'] ?? 0);
if ($resetId <= 0) {
Router::redirect('password/forgot');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!Session::checkCsrfToken()) {
$errors = [t('Form expired, please try again')];
} else {
$result = PasswordResetService::resetPassword($resetId, $password, $password2);
if ($result['ok'] ?? false) {
unset($_SESSION['password_reset_id']);
unset($_SESSION['password_reset_email']);
Flash::success(t('Password updated'), 'login', 'password_updated');
Router::redirect('login');
} else {
$errors = $result['errors'] ?? [t('Password can not be updated')];
}
}
}
$passwordHints = UserService::passwordHints();
$passwordMinLength = UserService::passwordMinLength();
Buffer::set('title', t('Reset password'));