2026-02-04 23:31:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-03-06 11:28:22 +01:00
|
|
|
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
|
|
|
|
2026-03-06 11:28:22 +01:00
|
|
|
$sessionStore = app(SessionStoreInterface::class);
|
|
|
|
|
|
2026-03-04 15:56:58 +01:00
|
|
|
$request = requestInput();
|
2026-02-04 23:31:53 +01:00
|
|
|
$error = false;
|
2026-02-11 19:28:12 +01:00
|
|
|
if (!allowRegistration()) {
|
2026-03-05 11:17:42 +01:00
|
|
|
Flash::error(t('Registration is currently disabled'), 'login', 'registration_disabled');
|
|
|
|
|
Router::redirect('login');
|
2026-02-11 19:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-07 22:54:33 +01:00
|
|
|
if ($request->isMethod('POST')) {
|
2026-04-24 19:10:37 +02:00
|
|
|
if (!actionRequireCsrf('register', flashOnFailure: false, redirectOnFailure: false)) {
|
2026-03-07 22:54:33 +01:00
|
|
|
$error = t('Form expired, please try again');
|
|
|
|
|
} elseif ($request->hasBody('email')) {
|
|
|
|
|
$authService = (app(AuthServicesFactory::class))->createAuthService();
|
|
|
|
|
$firstName = $request->bodyString('first_name');
|
|
|
|
|
$lastName = $request->bodyString('last_name');
|
|
|
|
|
$email = $request->bodyString('email');
|
|
|
|
|
$password = (string) $request->body('password', '');
|
|
|
|
|
$password2 = (string) $request->body('password2', '');
|
2026-02-04 23:31:53 +01:00
|
|
|
|
2026-03-07 22:54:33 +01:00
|
|
|
$result = $authService->register([
|
|
|
|
|
'first_name' => $firstName,
|
|
|
|
|
'last_name' => $lastName,
|
|
|
|
|
'email' => $email,
|
|
|
|
|
'password' => $password,
|
|
|
|
|
'password2' => $password2,
|
|
|
|
|
]);
|
2026-02-04 23:31:53 +01:00
|
|
|
|
2026-03-07 22:54:33 +01:00
|
|
|
if (!($result['ok'] ?? false)) {
|
|
|
|
|
$error = $result['error'] ?? t('User can not be registered');
|
|
|
|
|
} else {
|
|
|
|
|
// Store email in session for verify-email page
|
|
|
|
|
$sessionStore->set('email_verification_email', $result['email'] ?? $email);
|
|
|
|
|
Flash::success(t('Registration successful! Please check your email for the verification code.'), 'verify-email', 'registration_success');
|
|
|
|
|
Router::redirect('verify-email');
|
|
|
|
|
}
|
2026-03-05 11:17:42 +01:00
|
|
|
} else {
|
2026-03-07 22:54:33 +01:00
|
|
|
$error = t('User can not be registered');
|
2026-03-05 11:17:42 +01:00
|
|
|
}
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
2026-02-23 12:58:19 +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();
|