34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
|
|
use MintyPHP\Buffer;
|
|
use MintyPHP\Router;
|
|
use MintyPHP\Service\Auth\AuthServicesFactory;
|
|
use MintyPHP\Session;
|
|
use MintyPHP\Support\Flash;
|
|
|
|
$request = requestInput();
|
|
$errorBag = formErrors();
|
|
$errors = [];
|
|
$email = trim((string) $request->body('email', ''));
|
|
$passwordResetService = (app(AuthServicesFactory::class))->createPasswordResetService();
|
|
|
|
if ($request->isMethod('POST')) {
|
|
if (!Session::checkCsrfToken()) {
|
|
$errorBag->addGlobal(t('Form expired, please try again'));
|
|
} elseif ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$errorBag->addGlobal(t('Please enter a valid email address'));
|
|
} else {
|
|
$passwordResetService->requestReset($email);
|
|
$_SESSION['password_reset_email'] = $email;
|
|
Flash::success(
|
|
t('If the email exists, a verification code has been sent.'),
|
|
'password/verify',
|
|
'reset_requested'
|
|
);
|
|
Router::redirect('password/verify');
|
|
}
|
|
}
|
|
|
|
$errors = $errorBag->toFlatList();
|
|
Buffer::set('title', t('Forgot password'));
|