design login page
This commit is contained in:
1 parent
7c48e66677
commit
82efafb33b
1 file changed
+144
-34
+144
-34
@@ -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>
|
||||||
</head>
|
<style>
|
||||||
<body>
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
<input id="username"><br>
|
body {
|
||||||
<input type="password" id="password">
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #f6f8fa;
|
||||||
|
}
|
||||||
|
|
||||||
<button onclick="login()">Submit</button>
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
<script>
|
.login-card h1 {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
const couchDB = new CouchDB();
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 0.3rem;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
async function getData() {
|
input {
|
||||||
let res = await couchDB.get("users");
|
width: 100%;
|
||||||
if (!res) res = {};
|
padding: 0.5rem 0.75rem;
|
||||||
return res;
|
margin-bottom: 1rem;
|
||||||
}
|
border: 1px solid #d1d5da;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
async function login() {
|
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>
|
||||||
|
<body>
|
||||||
|
<div class="login-card">
|
||||||
|
<h1>Sign in</h1>
|
||||||
|
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="username"
|
||||||
|
name="username"
|
||||||
|
autocomplete="username"
|
||||||
|
autocapitalize="off"
|
||||||
|
autocorrect="off"
|
||||||
|
required
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
const couchDB = new CouchDB();
|
||||||
|
|
||||||
|
async function getData() {
|
||||||
|
try {
|
||||||
|
const res = await couchDB.get("users");
|
||||||
|
return res || {};
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to get users:", e);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
}
|
</body>
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
Reference in new issue
Block a user