Skip to content

Commit

Permalink
Update login
Browse files Browse the repository at this point in the history
  • Loading branch information
Usbac committed Sep 25, 2024
1 parent 1332cb3 commit 15ffa89
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions app/bootstrap/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@

$router->post('json:admin/login', function() use ($user_mod, $lang) {
$errors = $user_mod->handleLogin($_POST['email'], $_POST['password']);
$success = empty($errors);

return json_encode([
'success' => $success,
'msg' => $success ? $lang->get('sign_in_success') : '',
'success' => empty($errors),
'msg' => null,
'errors' => $errors,
]);
});
Expand Down
1 change: 0 additions & 1 deletion app/languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
'session_lifetime_description' => 'PHP Session lifetime in seconds (e.g. 3600 = 1 hour)',
'settings' => 'Settings',
'sign_in' => 'Sign in',
'sign_in_success' => 'You are now logged in. You will be redirected shortly.',
'site_footer' => 'Site footer',
'site_footer_description' => 'Code here will be injected into the footer of all pages.',
'site_header' => 'Site header',
Expand Down
1 change: 0 additions & 1 deletion app/languages/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
'session_lifetime_description' => 'Tiempo de la sesión de PHP en segundos (p.ej. 3600 = 1 hora)',
'settings' => 'Configuración',
'sign_in' => 'Iniciar sesión',
'sign_in_success' => 'Has iniciado sesión. Serás redirigido en breve.',
'site_footer' => 'Footer de la página',
'site_footer_description' => 'Este código se añadirá al footer de todas las páginas.',
'site_header' => 'Header de la página',
Expand Down
6 changes: 4 additions & 2 deletions app/views/admin/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
<script>
document.getElementById('login-form').addEventListener('submit', event => {
event.preventDefault();
Form.send('/admin/login', 'login-form', event.target.querySelector('[type="submit"]')).then(res => {
let btn = event.target.querySelector('[type="submit"]');
Form.send('/admin/login', 'login-form', btn).then(res => {
if (res.success) {
setTimeout(() => location.reload(), 3000);
location.reload();
btn.setAttribute('disabled', 'disabled');
}
});
});
Expand Down
4 changes: 3 additions & 1 deletion public/assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ class Form {
});

if (res?.success) {
Snackbar.show(res?.msg ? res.msg : LANG.done);
if (res?.msg !== null) {
Snackbar.show(res?.msg ? res.msg : LANG.done);
}
} else if (res?.errors?.hasOwnProperty(0)) {
Snackbar.show(res.errors[0], false);
}
Expand Down

0 comments on commit 15ffa89

Please sign in to comment.