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

47 lines
1.6 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\Service\User\UserServicesFactory;
use MintyPHP\Support\Flash;
2026-02-04 23:31:53 +01:00
$sessionStore = app(SessionStoreInterface::class);
$session = $sessionStore->all();
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
$password = (string) $request->body('password', '');
$password2 = (string) $request->body('password2', '');
$passwordResetService = (app(AuthServicesFactory::class))->createPasswordResetService();
2026-02-04 23:31:53 +01:00
$resetId = (int) ($session['password_reset_id'] ?? 0);
2026-02-04 23:31:53 +01:00
if ($resetId <= 0) {
Router::redirect('password/forgot');
}
2026-03-04 15:56:58 +01:00
if ($request->isMethod('POST')) {
if (!actionRequireCsrf('password/reset', 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
} else {
2026-02-23 12:58:19 +01:00
$result = $passwordResetService->resetPassword($resetId, $password, $password2);
2026-02-04 23:31:53 +01:00
if ($result['ok'] ?? false) {
$sessionStore->remove('password_reset_id');
$sessionStore->remove('password_reset_email');
2026-02-04 23:31:53 +01:00
Flash::success(t('Password updated'), 'login', 'password_updated');
Router::redirect('login');
} else {
2026-03-04 15:56:58 +01:00
$errorBag->merge($result['errors'] ?? [t('Password can not be updated')]);
2026-02-04 23:31:53 +01:00
}
}
}
2026-03-04 15:56:58 +01:00
$userPasswordPolicyService = (app(UserServicesFactory::class))->createUserPasswordPolicyService();
2026-02-23 12:58:19 +01:00
$passwordHints = $userPasswordPolicyService->hints();
$passwordMinLength = $userPasswordPolicyService->minLength();
2026-02-04 23:31:53 +01:00
2026-03-04 15:56:58 +01:00
$errors = $errorBag->toFlatList();
2026-02-04 23:31:53 +01:00
Buffer::set('title', t('Reset password'));