<body>
<div id="login-background">
<div id="login">
- <label id="username-label" for="username">username</label>
+ <label id="username-label" for="username-input">username</label>
<input id="username-input" />
- <label id="password-label" for="password">password</label>
+ <label id="password-label" for="password-input">password</label>
<input id="password-input" type="password" />
+ <label id="password-confirm-label" class="hidden" for="password-confirm-input">confirm password</label>
+ <input id="password-confirm-input" class="hidden" type="password" />
<button id="login-button">Sign In</button>
- <p id="login-error"></p>
+ <div id="login-text-container">
+ <p id="login-error"></p>
+ <p id="sign-up">Sign Up</p>
+ </div>
</div>
</div>
<div id="game-tile-background">
const svgns = "http://www.w3.org/2000/svg";
+import { Auth } from "./auth.js";
import { MainMenu } from "./mainmenu.js";
import { GameList } from "./gamelist.js";
import { Chatroom } from "./chatroom.js";
const message = JSON.parse(msg.data);
console.log("<<", message);
switch (message.type) {
+ case "CreateUserSuccess":
+ document.getElementById("password-input").value = "";
+ document.getElementById("password-confirm-input").value = "";
+ this.show_login("New user created");
+ this.state = "Connected";
+ break;
+ case "CreateUserFailure":
+ this.show_create_user(message.reason);
+ this.state = "Connected";
+ break;
case "LoginAuthChallenge":
this.send(this.auth.challenge_response(message.challenge));
this.state = "LoginAuthResponseSent";
document.getElementById("login-error").innerText = "";
}
document.getElementById("login-background").classList.remove("hidden");
+ document.getElementById("password-confirm-label").classList.add("hidden");
+ document.getElementById("password-confirm-input").classList.add("hidden");
document.getElementById("login-button").onclick = this.login_all_sockets;
document.getElementById("password-input").onchange = this.login_all_sockets;
+ document.getElementById("login-button").innerText = "Sign In";
+ document.getElementById("sign-up").onclick = () => this.show_create_user();
+ }
+
+ show_create_user(error) {
+ if (error) {
+ document.getElementById("login-error").classList.remove("hidden");
+ document.getElementById("login-error").innerText = error;
+ } else {
+ document.getElementById("login-error").classList.add("hidden");
+ document.getElementById("login-error").innerText = "";
+ }
+ document.getElementById("login-background").classList.remove("hidden");
+ document.getElementById("password-confirm-label").classList.remove("hidden");
+ document.getElementById("password-confirm-input").classList.remove("hidden");
+ document.getElementById("sign-up").classList.add("hidden");
+ document.getElementById("login-button").innerText = "Sign Up";
+ document.getElementById("password-input").onchange = () => {};
+ document.getElementById("login-button").onclick = () => {
+ const username = document.getElementById("username-input").value;
+ const password = document.getElementById("password-input").value;
+ const confirm = document.getElementById("password-confirm-input").value;
+ if (confirm != password) {
+ this.show_create_user("Passwords do not match");
+ } else {
+ this.send(new Auth(username, password).create_user_message());
+ }
+ };
}
create_game_display(summary, actions) {