diff --git a/data/security/securitylog.txt b/data/security/securitylog.txt index d146afb..2eee11f 100644 --- a/data/security/securitylog.txt +++ b/data/security/securitylog.txt @@ -8,3 +8,11 @@ 127.0.0.1;2023-12-25 06:20:18;login: authcode wrong or outdated. 127.0.0.1;2023-12-25 06:20:35;login: user not found 127.0.0.1;2023-12-25 09:12:05;login: wrong password +127.0.0.1;2023-12-27 11:17:43;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:21:21;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:24:01;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:25:07;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:30:28;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:31:36;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:31:52;login: authcode wrong or outdated. +127.0.0.1;2023-12-27 11:32:10;login: authcode wrong or outdated. diff --git a/system/typemill/Controllers/ControllerWebAuth.php b/system/typemill/Controllers/ControllerWebAuth.php index 6727498..1851e43 100644 --- a/system/typemill/Controllers/ControllerWebAuth.php +++ b/system/typemill/Controllers/ControllerWebAuth.php @@ -26,7 +26,9 @@ class ControllerWebAuth extends Controller $validation = new Validation(); $securitylog = $this->settings['securitylog'] ?? false; $authcodeactive = $this->settings['authcode'] ?? false; - + $authtitle = Translations::translate('Auth code missing?'); + $authtext = Translations::translate('If you did not receive an email with an authentication code, then the username or password you entered was wrong. Please try again.'); + if($validation->signin($input) !== true) { if($securitylog) @@ -72,6 +74,8 @@ class ControllerWebAuth extends Controller # show authcode page return $this->c->get('view')->render($response, 'auth/authcode.twig', [ 'username' => $userdata['username'], + 'authtitle' => $authtitle, + 'authtext' => $authtext ]); } @@ -100,7 +104,7 @@ class ControllerWebAuth extends Controller $mail = new SimpleMail($settings); $subject = Translations::translate('Your authentication code for Typemill'); - $message = Translations::translate('Use the following authentication code to login into Typemill cms') . ': ' . $authcodevalue; + $message = Translations::translate('Use the following authentication code to login into Typemill') . ': ' . $authcodevalue; $send = $mail->send($userdata['email'], $subject, $message); @@ -108,8 +112,8 @@ class ControllerWebAuth extends Controller if(!$send) { - $title = Translations::translate('Error sending email'); - $message = Translations::translate('Dear ') . $userdata['username'] . ', ' . Translations::translate('we could not send the email with the authentication code to your address. Reason: ') . $mail->error; + $authtitle = Translations::translate('Error sending email'); + $authtext = Translations::translate('We could not send the email with the authentication code to your address. Reason: ') . $mail->error; } else { @@ -120,7 +124,9 @@ class ControllerWebAuth extends Controller # show authcode page return $this->c->get('view')->render($response, 'auth/authcode.twig', [ - 'username' => $userdata['username'], + 'username' => $userdata['username'], + 'authtitle' => $authtitle, + 'authtext' => $authtext ]); } @@ -139,8 +145,6 @@ class ControllerWebAuth extends Controller $user->login(); -# return $response->withHeader('Location', $this->routeParser->urlFor('settings.show'))->withStatus(302); - # if user is allowed to view content-area $acl = $this->c->get('acl'); if($acl->hasRole($userdata['userrole']) && $acl->isAllowed($userdata['userrole'], 'content', 'view')) @@ -154,7 +158,7 @@ class ControllerWebAuth extends Controller } - # login user with valid authcode + # login a user with valid authcode public function loginWithAuthcode(Request $request, Response $response) { $input = $request->getParsedBody(); @@ -204,9 +208,9 @@ class ControllerWebAuth extends Controller } # add the device fingerprint if not set yet - $fingerprints = $userdata['fingerprints'] ?? []; - $fingerprint = $this->generateDeviceFingerprint(); - if(!$this->findDeviceFingerprint($fingerprint, $fingerprints)) + $fingerprints = $userdata['fingerprints'] ?? []; + $fingerprint = $this->generateDeviceFingerprint(); + if(!$this->findDeviceFingerprint($fingerprint, $userdata)) { $fingerprints[] = $fingerprint; $user->setValue('fingerprints', $fingerprints); @@ -231,14 +235,7 @@ class ControllerWebAuth extends Controller } - /** - * log out a user - * - * @param obj $request the slim request object - * @param obj $response the slim response object - * @return obje $response with redirect to route - */ - + # log out a user public function logout(Request $request, Response $response) { \Typemill\Static\Session::stopSession(); diff --git a/system/typemill/Models/SimpleMail.php b/system/typemill/Models/SimpleMail.php index d86bb36..ed2b092 100644 --- a/system/typemill/Models/SimpleMail.php +++ b/system/typemill/Models/SimpleMail.php @@ -2,6 +2,8 @@ namespace Typemill\Models; +use Typemill\Static\Translations; + class SimpleMail { private $from = false; @@ -28,11 +30,11 @@ class SimpleMail } } - public function sendEmail(string $to, string $subject, string $message) + public function send(string $to, string $subject, string $message) { if(!$this->from) { - $this->error = 'You need to add a email address into the settings.'; + $this->error = Translations::translate('Email address in system settings is missing.'); return false; } diff --git a/system/typemill/author/auth/authcode.twig b/system/typemill/author/auth/authcode.twig index 44372ec..f44f97f 100644 --- a/system/typemill/author/auth/authcode.twig +++ b/system/typemill/author/auth/authcode.twig @@ -11,7 +11,7 @@

Authentication Code

-

Enter the auth code from the e-mail you got: +

{{ translate('Enter the authentication code from your email:') }}

@@ -24,7 +24,7 @@ pattern="[0-9]" maxlength="1" oninput="moveToNextField(this)" - class="mr-2 form-control block w-full px-3 py-3 text-xl text-center font-normal text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 transition ease-in-out m-0 focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-non" + class="mr-2 form-control block w-full px-3 py-3 text-xl text-center font-bold text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 transition ease-in-out m-0 focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-non" required> @@ -88,14 +88,15 @@ } } -
+
-

{{ translate('Auth code missing?') }}

-

{{ translate('If you did not receive an email with an authentication code, then the username or password you entered was wrong. Please try again.') }}

+

{{ authtitle }}

+

{{ authtext }}

+ → {{ translate('Back to login') }}