design login page

This commit is contained in:
Araz Mazaheri committed 2025-12-30 19:24:33 +01:00
1 parent 7c48e66677
commit 82efafb33b
1 file changed
+133 -23
+133 -23
View File
@@ -1,50 +1,160 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title> <title>Login</title>
<link rel="stylesheet" href="./lib/basic.css"> <link rel="stylesheet" href="./lib/basic.css" />
<script src="./auth.js"></script> <script src="./auth.js" defer></script>
<script src="./lib/basic.js"></script> <script src="./lib/basic.js" defer></script>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f6f8fa;
}
.login-card {
background-color: #fff;
padding: 2.5rem 2rem;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
width: 100%;
max-width: 400px;
}
.login-card h1 {
text-align: center;
margin-bottom: 1.5rem;
font-size: 1.5rem;
}
label {
display: block;
margin-bottom: 0.3rem;
font-weight: 600;
font-size: 0.9rem;
}
input {
width: 100%;
padding: 0.5rem 0.75rem;
margin-bottom: 1rem;
border: 1px solid #d1d5da;
border-radius: 6px;
font-size: 1rem;
}
button {
width: 100%;
padding: 0.6rem;
background-color: #2ea44f;
color: #fff;
border: none;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
}
button:hover {
background-color: #279f43;
}
.signup-text {
text-align: center;
margin-top: 1rem;
font-size: 0.9rem;
}
.signup-text a {
color: #0366d6;
text-decoration: none;
}
.signup-text a:hover {
text-decoration: underline;
}
</style>
</head> </head>
<body> <body>
<div class="login-card">
<h1>Sign in</h1>
<input id="username"><br> <label for="username">Username</label>
<input type="password" id="password"> <input
type="text"
id="username"
name="username"
autocomplete="username"
autocapitalize="off"
autocorrect="off"
required
autofocus
/>
<button onclick="login()">Submit</button> <label for="password">Password</label>
<input
type="password"
id="password"
name="password"
autocomplete="current-password"
required
/>
<button type="button" onclick="login()">Sign in</button>
<div class="signup-text">
Don't have an account yet? <a href="signup.html">Sign up</a>
</div>
</div>
<script> <script>
const couchDB = new CouchDB(); const couchDB = new CouchDB();
async function getData() { async function getData() {
let res = await couchDB.get("users"); try {
if (!res) res = {}; const res = await couchDB.get("users");
return res; return res || {};
} catch (e) {
console.error("Failed to get users:", e);
return {};
}
} }
async function login() { async function login() {
const data = await getData(); const data = await getData();
const username = getId("username").value.toLowerCase(); const username = document
const password = getId("password").value; .getElementById("username")
.value.trim()
.toLowerCase();
const password = document.getElementById("password").value;
const user = data[username]; const user = data[username];
//{"turtle":{"password": "password","level":1}}
if (user == undefined) { if (user == undefined) {
alert("Falscher Nutzername!"); return alert("User doesn't exist!");
return;
} }
if (user.password != password) { if (user.password != password) {
alert("Falsches Passwort!"); return alert("Incorrect password!");
}
if (user.role === "student") {
location.href =
"./student/uebersicht.html?user=" + username;
return;
} else {
location.href = "./prof/uebersicht.html?user=" + username;
return; return;
} }
location.href = "./prof/uebersicht.html?user=" + username;
} }
</script> </script>
</body> </body>
</html> </html>