Files
breadcrumb-the-shire/pages/auth/forgot().php

36 lines
1.2 KiB
PHP
Raw Normal View History

2026-02-04 23:31:53 +01:00
<?php
use MintyPHP\Buffer;
use MintyPHP\Http\SessionStoreInterface;
2026-02-04 23:31:53 +01:00
use MintyPHP\Router;
2026-02-23 12:58:19 +01:00
use MintyPHP\Service\Auth\AuthServicesFactory;
use MintyPHP\Support\Flash;
2026-02-04 23:31:53 +01:00
$sessionStore = app(SessionStoreInterface::class);
2026-03-04 15:56:58 +01:00
$request = requestInput();
$errorBag = formErrors();
2026-02-04 23:31:53 +01:00
$errors = [];
2026-03-04 15:56:58 +01:00
$email = trim((string) $request->body('email', ''));
$passwordResetService = (app(AuthServicesFactory::class))->createPasswordResetService();
2026-02-04 23:31:53 +01:00
2026-03-04 15:56:58 +01:00
if ($request->isMethod('POST')) {
if (!actionRequireCsrf('password/forgot', flashOnFailure: false, redirectOnFailure: false)) {
2026-03-04 15:56:58 +01:00
$errorBag->addGlobal(t('Form expired, please try again'));
2026-02-04 23:31:53 +01:00
} elseif ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
2026-03-04 15:56:58 +01:00
$errorBag->addGlobal(t('Please enter a valid email address'));
2026-02-04 23:31:53 +01:00
} else {
2026-02-23 12:58:19 +01:00
$passwordResetService->requestReset($email);
$sessionStore->set('password_reset_email', $email);
2026-02-04 23:31:53 +01:00
Flash::success(
t('If the email exists, a verification code has been sent.'),
'password/verify',
'reset_requested'
);
Router::redirect('password/verify');
}
}
2026-03-04 15:56:58 +01:00
$errors = $errorBag->toFlatList();
2026-02-04 23:31:53 +01:00
Buffer::set('title', t('Forgot password'));