60 lines
1.2 KiB
HTML
60 lines
1.2 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login</title>
|
|
<link rel="stylesheet" href="./lib/basic.css">
|
|
<script src="./auth.js"></script>
|
|
<script src="./lib/basic.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<input id="username"><br>
|
|
<input type="password" id="password">
|
|
|
|
<button onclick="login()">Submit</button>
|
|
|
|
<script>
|
|
|
|
const couchDB = new CouchDB();
|
|
|
|
async function getData() {
|
|
let res = await couchDB.get("users");
|
|
if (!res) res = {};
|
|
return res;
|
|
}
|
|
|
|
async function login() {
|
|
const data = await getData();
|
|
const username = getId("username").value.toLowerCase();
|
|
const password = getId("password").value;
|
|
|
|
const user = data[username];
|
|
//{"turtle":{"password": "password","level":1}}
|
|
if (user == undefined) {
|
|
alert("Falscher Nutzername!");
|
|
return;
|
|
}
|
|
if (user.password != password) {
|
|
alert("Falsches Passwort!");
|
|
return;
|
|
}
|
|
|
|
switch (user.role) {
|
|
case "professor":
|
|
location.href = "./prof/uebersicht.html?user=" + username;
|
|
return;
|
|
case "student":
|
|
location.href = "./student/uebersicht.html?user=" + username;
|
|
return;
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |