55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import { client, navigateTo } from "../../index.js";
|
|
import AbstractNonAuthentifiedView from "../AbstractNonAuthentified.js";
|
|
|
|
async function login()
|
|
{
|
|
let username = document.getElementById("username").value;
|
|
let password = document.getElementById("password").value;
|
|
|
|
let response_data = await client.login(username, password);
|
|
|
|
if (response_data == null)
|
|
{
|
|
navigateTo("/home");
|
|
return;
|
|
}
|
|
|
|
["username", "user", "password"].forEach(error_field => {
|
|
let error_display = document.getElementById(`error_${error_field}`);
|
|
if (error_display != null)
|
|
error_display.innerHTML = "";
|
|
});
|
|
|
|
Object.keys(response_data).forEach(error_field => {
|
|
let error_display = document.getElementById(`error_${error_field}`);
|
|
if (error_display != null)
|
|
error_display.innerHTML = response_data[error_field];
|
|
});
|
|
}
|
|
|
|
export default class extends AbstractNonAuthentifiedView {
|
|
constructor(params) {
|
|
super(params, "Login", "/home");
|
|
}
|
|
|
|
async postInit()
|
|
{
|
|
document.getElementById("button").onclick = login;
|
|
}
|
|
|
|
async getHtml() {
|
|
return `
|
|
<div class=form>
|
|
<label>Login</label>
|
|
<link rel="stylesheet" href="static/css/accounts/login.css">
|
|
<input type="text" id="username" placeholder="username">
|
|
<span id="error_username"></span>
|
|
<input type="password" id="password" placeholder="password">
|
|
<span id="error_password"></span>
|
|
<input type="button" value="login" id="button">
|
|
<span id="error_user"></span>
|
|
<a href="/register" class="nav__link" data-link>Register</a>
|
|
</div>
|
|
`;
|
|
}
|
|
} |