2023-11-23 11:26:09 -05:00
|
|
|
import AbstractView from "../AbstractView.js";
|
2023-11-27 13:11:15 -05:00
|
|
|
import { client, navigateTo } from "../../index.js";
|
2023-11-23 11:26:09 -05:00
|
|
|
|
|
|
|
async function login()
|
|
|
|
{
|
|
|
|
let username = document.getElementById("username").value;
|
|
|
|
let password = document.getElementById("password").value;
|
|
|
|
|
2023-11-29 10:05:49 -05:00
|
|
|
let response_data = await client.login(username, password);
|
2023-11-27 13:11:15 -05:00
|
|
|
|
2023-11-29 10:05:49 -05:00
|
|
|
if (response_data == null)
|
2023-11-27 13:11:15 -05:00
|
|
|
{
|
|
|
|
navigateTo("/home");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-27 07:55:05 -05:00
|
|
|
["username", "user", "password"].forEach(error_field => {
|
|
|
|
let error_display = document.getElementById(`error_${error_field}`);
|
|
|
|
if (error_display != null)
|
|
|
|
error_display.innerHTML = "";
|
|
|
|
});
|
2023-11-23 11:26:09 -05:00
|
|
|
|
2023-11-27 07:55:05 -05:00
|
|
|
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];
|
2023-11-23 11:26:09 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class extends AbstractView {
|
|
|
|
constructor(params) {
|
|
|
|
super(params);
|
|
|
|
this.setTitle("Login");
|
2023-11-27 13:11:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async postInit()
|
|
|
|
{
|
2023-11-29 10:18:54 -05:00
|
|
|
document.getElementById("button").onclick = login;
|
2023-11-29 10:10:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async getHtml() {
|
2023-11-29 10:05:49 -05:00
|
|
|
if (await client.isAuthentificate())
|
|
|
|
{
|
|
|
|
navigateTo("/home")
|
|
|
|
return;
|
|
|
|
}
|
2023-11-23 11:26:09 -05:00
|
|
|
return `
|
2023-11-27 07:55:05 -05:00
|
|
|
<div class=form>
|
2023-11-27 09:32:33 -05:00
|
|
|
<label>Login</label>
|
2023-11-27 07:55:05 -05:00
|
|
|
<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>
|
2023-11-27 13:11:15 -05:00
|
|
|
<input type="button" value="login" id="button">
|
2023-11-27 07:55:05 -05:00
|
|
|
<span id="error_user"></span>
|
|
|
|
<a href="/register" class="nav__link" data-link>Register</a>
|
|
|
|
</div>
|
2023-11-23 11:26:09 -05:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
}
|