48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import { client, navigateTo } from "../../index.js";
|
|
import { clear, fill_errors } from "../../utils/formUtils.js";
|
|
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
|
|
|
|
async function login()
|
|
{
|
|
let username = document.getElementById("username-input").value;
|
|
let password = document.getElementById("password-input").value;
|
|
|
|
let response_data = await client.login(username, password);
|
|
|
|
if (response_data == null)
|
|
{
|
|
navigateTo("/home");
|
|
return;
|
|
}
|
|
|
|
clear("innerHTML", ["username", "user", "password"]);
|
|
fill_errors(response_data, "innerHTML");
|
|
}
|
|
|
|
export default class extends AbstractNonAuthentifiedView {
|
|
constructor(params) {
|
|
super(params, "Login", "/home");
|
|
}
|
|
|
|
async postInit()
|
|
{
|
|
document.getElementById("login-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-input" placeholder="username">
|
|
<span id="username"></span>
|
|
<input type="password" id="password-input" placeholder="password">
|
|
<span id="password"></span>
|
|
<input type="button" value="Login" id="login-button">
|
|
<span id="user"></span>
|
|
<a href="/register" class="nav__link" data-link>Register</a>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|