use post init to onclick
This commit is contained in:
parent
d490208ffa
commit
3f3ab52a09
@ -1,5 +1,5 @@
|
|||||||
import AbstractView from "../AbstractView.js";
|
import AbstractView from "../AbstractView.js";
|
||||||
import { client } from "../../index.js";
|
import { client, navigateTo } from "../../index.js";
|
||||||
|
|
||||||
async function login()
|
async function login()
|
||||||
{
|
{
|
||||||
@ -8,7 +8,13 @@ async function login()
|
|||||||
|
|
||||||
let response = await client.login(username, password);
|
let response = await client.login(username, password);
|
||||||
let response_data = await response.json();
|
let response_data = await response.json();
|
||||||
|
|
||||||
|
if (response_data == "user connected")
|
||||||
|
{
|
||||||
|
navigateTo("/home");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
["username", "user", "password"].forEach(error_field => {
|
["username", "user", "password"].forEach(error_field => {
|
||||||
let error_display = document.getElementById(`error_${error_field}`);
|
let error_display = document.getElementById(`error_${error_field}`);
|
||||||
if (error_display != null)
|
if (error_display != null)
|
||||||
@ -26,11 +32,11 @@ export default class extends AbstractView {
|
|||||||
constructor(params) {
|
constructor(params) {
|
||||||
super(params);
|
super(params);
|
||||||
this.setTitle("Login");
|
this.setTitle("Login");
|
||||||
document.body.addEventListener("click", e => {
|
}
|
||||||
e.preventDefault();
|
|
||||||
if (e.target.type == "button")
|
async postInit()
|
||||||
login();
|
{
|
||||||
});
|
document.getElementById("button").onclick = login;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHtml() {
|
async getHtml() {
|
||||||
@ -42,7 +48,7 @@ export default class extends AbstractView {
|
|||||||
<span id="error_username"></span>
|
<span id="error_username"></span>
|
||||||
<input type="password" id="password" placeholder="password">
|
<input type="password" id="password" placeholder="password">
|
||||||
<span id="error_password"></span>
|
<span id="error_password"></span>
|
||||||
<input type="button" value="login">
|
<input type="button" value="login" id="button">
|
||||||
<span id="error_user"></span>
|
<span id="error_user"></span>
|
||||||
<a href="/register" class="nav__link" data-link>Register</a>
|
<a href="/register" class="nav__link" data-link>Register</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,11 +26,11 @@ export default class extends AbstractView {
|
|||||||
constructor(params) {
|
constructor(params) {
|
||||||
super(params);
|
super(params);
|
||||||
this.setTitle("register");
|
this.setTitle("register");
|
||||||
document.body.addEventListener("click", e => {
|
}
|
||||||
e.preventDefault();
|
|
||||||
if (e.target.type == "button")
|
async postInit()
|
||||||
register();
|
{
|
||||||
});
|
document.getElementById("button").onclick = register;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getHtml() {
|
async getHtml() {
|
||||||
@ -42,7 +42,7 @@ export default class extends AbstractView {
|
|||||||
<span id="error_username"></span>
|
<span id="error_username"></span>
|
||||||
<input type="password" id="password" placeholder="password">
|
<input type="password" id="password" placeholder="password">
|
||||||
<span id="error_password"></span>
|
<span id="error_password"></span>
|
||||||
<input type="button" value="register">
|
<input type="button" value="register" id="button">
|
||||||
<span id="error_user"></span>
|
<span id="error_user"></span>
|
||||||
<a href="/login" class="nav__link" data-link>Login</a>
|
<a href="/login" class="nav__link" data-link>Login</a>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user