151 lines
4.4 KiB
HTML
151 lines
4.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>register - ZYM's Book Store</title>
|
|
<link rel="stylesheet" href="basic.css">
|
|
<style>
|
|
.register-box {
|
|
width: 300px;
|
|
padding: 20px;
|
|
border: 1px solid #ccc;
|
|
background-color: #fff;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 10px;
|
|
margin-bottom: 10px;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
button {
|
|
width: 100%;
|
|
padding: 10px;
|
|
background-color: #4caf50;
|
|
color: #fff;
|
|
border: none;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.info-box {
|
|
width: 300px;
|
|
padding: 20px;
|
|
border: 1px solid #ccc;
|
|
background-color: #fff;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>ZYM's Book Store</h1>
|
|
<div class="user-bar">
|
|
<span>Welcome, <span id="username">[Guest]</span></span>
|
|
<div class="action-button-container" onmouseover="showDropdown()" onmouseout="hideDropdown()">
|
|
<div class="action-button">Actions</div>
|
|
<div class="dropdown">
|
|
<div class="dropdown-content">
|
|
<a href="/login">Login</a>
|
|
<a href="#" onclick="(async () => { await Request('logout'); await UpdateUserInfo(); location.reload();})(); return false;">Logout</a>
|
|
<a href="/register">Register</a>
|
|
<a href="/passwd">Change Password</a>
|
|
<a href="/admin">Admin Panel</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="main-content">
|
|
<nav>
|
|
<a href="#">Search Books</a>
|
|
<a href="#">Purchase Books</a>
|
|
</nav>
|
|
<div class="content">
|
|
<div class="register-box">
|
|
<form onsubmit="console.log('trying register'); TryRegister(); return false;">
|
|
<input id="user_name" type="text" placeholder="Username" required>
|
|
<input id="password" type="password" placeholder="Password" required>
|
|
<input id="nickname" type="text" placeholder="Nickname" required>
|
|
<button type="submit">Register</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="/socket.io/socket.io.js"></script>
|
|
<script src="/communication.js"></script>
|
|
<script>
|
|
function showDropdown() {
|
|
document.querySelector('.dropdown-content').style.display = 'block';
|
|
}
|
|
|
|
function hideDropdown() {
|
|
document.querySelector('.dropdown-content').style.display = 'none';
|
|
}
|
|
function ChangeUsername(newUsername) {
|
|
document.getElementById('username').textContent = newUsername;
|
|
}
|
|
async function UpdateUserInfo(){
|
|
let nm=await GetMyName();
|
|
let pri=await GetMyPrivilege();
|
|
if(nm=='')
|
|
{
|
|
await RefreshSession();
|
|
nm=await GetMyName();
|
|
pri=await GetMyPrivilege();
|
|
}
|
|
if(pri==0)
|
|
{
|
|
ChangeUsername("[Guest]");
|
|
}
|
|
else if(pri==1)
|
|
{
|
|
ChangeUsername(nm);
|
|
}
|
|
else if(pri==3)
|
|
{
|
|
ChangeUsername(nm+" [Worker]");
|
|
}
|
|
else if(pri==7)
|
|
{
|
|
ChangeUsername(nm+" [Admin]");
|
|
}
|
|
}
|
|
document.addEventListener('SessionReady', async () => {
|
|
await UpdateUserInfo();
|
|
});
|
|
async function TryRegister()
|
|
{
|
|
console.log("TryRegister called");
|
|
var username = document.getElementById("user_name").value;
|
|
var password = document.getElementById("password").value;
|
|
var nick_name = document.getElementById("nickname").value;
|
|
var ret=await Request("register "+username+" "+password+" "+nick_name);
|
|
if(ret=="Invalid")
|
|
{
|
|
alert("Invalid username or password");
|
|
}
|
|
else
|
|
{
|
|
// 删除注册框,在中间显示“注册成功”,三秒后自动跳转到首页
|
|
document.querySelector('.register-box').style.display = 'none';
|
|
document.querySelector('.content').innerHTML = '<div class="info-box"><h2>Register Success</h2><p>Redirecting to home page in 3 seconds...</p></div>';
|
|
setTimeout(function(){window.location.href="/";},3000);
|
|
}
|
|
}
|
|
</script>
|
|
<script src="/sessioninit.js"></script>
|
|
</body>
|
|
</html> |