-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·108 lines (85 loc) · 3.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="style.css" rel="stylesheet">
<title>Hello, world!</title>
</head>
<body>
<div class="wrapper fadeInDown -hidden" id="formWrapper">
<div id="formContent">
<h2 class="fadeIn first">Anmeldeformular</h2>
<!-- Login Form -->
<form>
<input type="text" id="login" class="fadeIn second" name="login" placeholder="login">
<input type="text" id="password" class="fadeIn third" name="login" placeholder="password">
<input type="submit" id="submit" class="fadeIn fourth" value="Anmelden">
</form>
<div id="output"></div>
</div>
</div>
<div class="wrapper fadeInDown -hidden" id="helloWrapper">
<div id="helloContent">
<h2 class="fadeIn first">Hello <span id="helloUsername"></span></h2>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script>
function dothelogin() {
var username = document.getElementById("login").value;
var password = document.getElementById("password").value;
var url = new URL('http://lo.projekt-login.ch/login.php')
var params = {
username: username,
password: password
}
url.search = new URLSearchParams(params).toString();
fetch(url)
.then(response => response.json())
.then(data => {
const output = document.getElementById("output");
const message = data.message;
let color_class = 'alert-danger';
output.innerHTML = "";
if (data.success) {
color_class = 'alert-success';
}
if (data.success) {
output.innerHTML = '<div class="alert ' + color_class + '" role="alert">Hallo ' + data.user.username + '</div>';
location.reload();
} else {
output.innerHTML = '<div class="alert ' + color_class + '" role="alert">' + message + '</div>';
}
console.log(data.user);
console.log(data.user.username);
localStorage.setItem("username", data.user.username);
});
}
document.getElementById("submit").addEventListener("click", (event) => {
event.preventDefault();
dothelogin();
});
const username = localStorage.getItem('username');
let wrapper = null;
if (username) {
console.log('show hello box');
wrapper = document.getElementById("helloWrapper");
const usernameBox = document.getElementById('helloUsername');
usernameBox.innerHTML = username;
}
else {
wrapper = document.getElementById("formWrapper");
}
wrapper.classList.remove("-hidden");
</script>
</body>
</html>