ft_transcendence/frontend/static/js/views/accounts/LoginView.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-11-27 13:11:15 -05:00
import { client, navigateTo } from "../../index.js";
import { clear, fill_errors } from "../../utils/formUtils.js";
import AbstractNonAuthentifiedView from "../abstracts/AbstractNonAuthentified.js";
2023-11-23 11:26:09 -05:00
async function login()
{
let username = document.getElementById("username-input").value;
let password = document.getElementById("password-input").value;
2023-11-23 11:26:09 -05:00
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;
}
clear("innerHTML", ["username", "user", "password"]);
fill_errors(response_data, "innerHTML");
2023-11-23 11:26:09 -05:00
}
2023-11-29 16:51:57 -05:00
export default class extends AbstractNonAuthentifiedView {
2023-11-23 11:26:09 -05:00
constructor(params) {
2023-11-30 07:05:46 -05:00
super(params, "Login", "/home");
2023-11-27 13:11:15 -05:00
}
async postInit()
{
document.getElementById("login-button").onclick = login;
}
async getHtml() {
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-12-16 04:39:07 -05:00
<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>
2023-11-27 07:55:05 -05:00
<a href="/register" class="nav__link" data-link>Register</a>
</div>
2023-11-23 11:26:09 -05:00
`;
}
}