front: redirect to last visited page after login
This commit is contained in:
@ -2,7 +2,7 @@ import { client, navigateTo } from "../../index.js";
|
||||
import { clear, fill_errors } from "../../utils/formUtils.js";
|
||||
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
|
||||
|
||||
async function login()
|
||||
async function login(redirectTo = '/home')
|
||||
{
|
||||
clear('innerHTML', ['username', 'password', 'login']);
|
||||
|
||||
@ -23,7 +23,7 @@ async function login()
|
||||
if (response.status == 200) {
|
||||
await client.notice.disconnect();
|
||||
await client.notice.connect();
|
||||
navigateTo("/home");
|
||||
navigateTo(redirectTo);
|
||||
} else {
|
||||
let error = await response.json();
|
||||
fill_errors(error, "innerHTML");
|
||||
@ -31,8 +31,9 @@ async function login()
|
||||
}
|
||||
|
||||
export default class extends AbstractNonAuthentifiedView {
|
||||
constructor(params) {
|
||||
super(params, "Login", "/home");
|
||||
constructor(params, lastUrlBeforeLogin = '/home') {
|
||||
super(params, "Login", lastUrlBeforeLogin);
|
||||
this.redirectTo = lastUrlBeforeLogin;
|
||||
}
|
||||
|
||||
async postInit()
|
||||
@ -40,15 +41,15 @@ export default class extends AbstractNonAuthentifiedView {
|
||||
let usernameField = document.getElementById('usernameInput');
|
||||
usernameField.addEventListener('keydown', ev => {
|
||||
if (ev.key === 'Enter')
|
||||
login();
|
||||
login(this.redirectTo);
|
||||
});
|
||||
usernameField.focus();
|
||||
let passwordField = document.getElementById('passwordInput');
|
||||
passwordField.addEventListener('keydown', ev => {
|
||||
if (ev.key === 'Enter')
|
||||
login();
|
||||
login(this.redirectTo);
|
||||
});
|
||||
document.getElementById('loginButton').onclick = login;
|
||||
document.getElementById('loginButton').onclick = _ => login(this.redirectTo);
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
|
Reference in New Issue
Block a user