identify user by username as well

This commit is contained in:
Bence Pőcze 2023-09-24 00:48:24 +02:00
parent 1156f84065
commit 69575fabf5
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D
3 changed files with 73 additions and 72 deletions

View File

@ -2,6 +2,7 @@
use DateInterval; use DateInterval;
use DateTime; use DateTime;
use Faker\Factory;
use SokoWeb\Http\Request; use SokoWeb\Http\Request;
use SokoWeb\Interfaces\Response\IContent; use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Interfaces\Response\IRedirect; use SokoWeb\Interfaces\Response\IRedirect;
@ -158,7 +159,7 @@ class LoginController
return new JsonContent(['success' => true]); return new JsonContent(['success' => true]);
} }
$user = $this->userRepository->getByEmail(\Container::$request->post('email')); $user = $this->userRepository->getByEmailOrUsername(\Container::$request->post('email'));
if ($user === null) { if ($user === null) {
if (strlen(\Container::$request->post('password')) < 6) { if (strlen(\Container::$request->post('password')) < 6) {
@ -189,7 +190,7 @@ class LoginController
return new JsonContent([ return new JsonContent([
'error' => [ 'error' => [
'errorText' => 'User found with the given email address, but the account is not activated. ' . 'errorText' => 'User found with the given email address / username, but the account is not activated. ' .
'Please check your email and click on the activation link!' 'Please check your email and click on the activation link!'
] ]
]); ]);
@ -483,12 +484,12 @@ class LoginController
} }
} }
$user = $this->userRepository->getByEmail(\Container::$request->post('email')); $user = $this->userRepository->getByEmailOrUsername(\Container::$request->post('email'));
if ($user === null) { if ($user === null) {
return new JsonContent([ return new JsonContent([
'error' => [ 'error' => [
'errorText' => 'No user found with the given email address. You can <a href="/signup" title="Sign up">sign up</a>!' 'errorText' => 'No user found with the given email address / username. You can <a href="/signup" title="Sign up">sign up</a>!'
] ]
]); ]);
} }
@ -498,7 +499,7 @@ class LoginController
return new JsonContent([ return new JsonContent([
'error' => [ 'error' => [
'errorText' => 'User found with the given email address, but the account is not activated. ' . 'errorText' => 'User found with the given email address / username, but the account is not activated. ' .
'Please check your email and click on the activation link!' 'Please check your email and click on the activation link!'
] ]
]); ]);

View File

@ -4,7 +4,7 @@
<h2>Login</h2> <h2>Login</h2>
<div class="box"> <div class="box">
<form id="loginForm" action="/login" method="post" data-redirect-on-success="<?= $redirectUrl ?>"> <form id="loginForm" action="/login" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" autocomplete="username" required autofocus> <input type="email" class="text big fullWidth" name="email" placeholder="Email address / username" autocomplete="username" required autofocus>
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" autocomplete="current-password" required minlength="6"> <input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" autocomplete="current-password" required minlength="6">
<p id="loginFormError" class="formError justify marginTop"></p> <p id="loginFormError" class="formError justify marginTop"></p>
<div class="right marginTop"> <div class="right marginTop">

View File

@ -6,7 +6,7 @@
<h2>Request password reset</h2> <h2>Request password reset</h2>
<div class="box"> <div class="box">
<form id="passwordResetForm" action="/password/requestReset" method="post" data-redirect-on-success="/password/requestReset/success"> <form id="passwordResetForm" action="/password/requestReset" method="post" data-redirect-on-success="/password/requestReset/success">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" autocomplete="username" value="<?= isset($email) ? $email : '' ?>" required autofocus> <input type="email" class="text big fullWidth" name="email" placeholder="Email address / username" autocomplete="username" value="<?= isset($email) ? $email : '' ?>" required autofocus>
<?php if (!empty($_ENV['RECAPTCHA_SITEKEY'])): ?> <?php if (!empty($_ENV['RECAPTCHA_SITEKEY'])): ?>
<div class="marginTop"> <div class="marginTop">
<div class="g-recaptcha" data-sitekey="<?= $_ENV['RECAPTCHA_SITEKEY'] ?>"></div> <div class="g-recaptcha" data-sitekey="<?= $_ENV['RECAPTCHA_SITEKEY'] ?>"></div>