-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.index.html
149 lines (129 loc) · 3.96 KB
/
default.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="fr" class="h-100">
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<link type="image/x-icon" rel="icon" href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAA114LAP///wApJSEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARMzMRAAAAATMzMzMQAAATMxERMzEAATMxIiITMxATMzEjMhMzMRMzMSIiEzMxMzMxIzMzMzMzMzEiIiEzMzMzMSMzMzMzMzMxIzITMzMTMzEjMhMzMRMzMSIjMzMxATMzERMzMxAAEzMzMzMxAAABMzMzMxAAAAARMzMRAADwDwAA4AcAAMADAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAAwAMAAOAHAADwDwAA">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<title>Login</title>
<style>
html,
body {
height: 100%;
}
body {
display: flex;
flex-wrap: wrap;
align-items: center;
padding-top: 40px;
padding-bottom: 40px;
background-color: #000;
color: #fff;
}
.form {
width: 100%;
max-width: 400px;
padding: 4em 2em;
margin: auto;
height: fit-content;
background: #222;
border-radius: 1em;
}
.form-input:focus {
border-color: #fff;
}
.form-input {
color: #fff;
background-color: #000;
padding: 0.5em;
border: 0;
display: block;
margin: 1em auto;
width: 80%;
}
.form-btn {
width: 80%;
margin: 2em 0 0 0;
}
.form-title {
margin: 0 0 2em 0;
}
.form-check-label {
color: #888;
font-style: italic;
}
.form-check-input {
background-color: #888;
}
.error {
background-color: #dc3545;
text-align: center;
border-radius: 1em;
width: 75%;
margin: 0.3em auto;
}
.footer {
width: 100%;
}
::placeholder {
color: #fff;
}
</style>
</head>
<body class="text-center">
<main class="form">
<form id="form" method="POST">
{{ if eq .state "out" }}
<h1 class="form-title">Login</h1>
<div class="error" id="error">{{ .error }}</div>
<input type="text" autocomplete="username" autocapitalize="none" class="form-input" name="username" placeholder="Username" id="username" autofocus>
<input type="password" autocomplete="current-password" autocapitalize="none" class="form-input" name="password" id="password" placeholder="Password">
<input class="form-check-input" type="checkbox" id="anyip" name="anyip" checked="false">
<label class="form-check-label" for="anyip">Stay connected from anywhere</label>
<button class="btn btn-primary form-btn" type="submit">Login</button>
{{ else }}
<h1 class="form-title">Welcome {{ .username }}</h1>
<div class="error" id="error">{{ .error }}</div>
<a href="/logout" class="btn btn-primary">Logout</a>
{{ end }}
<input type="hidden" name=csrf value="{{ .csrf }}">
</form>
</main>
<footer class="footer mt-auto py-3 bg-tranparent text-end">
<div class="container">
<span class="text-muted">You are : {{ .ip }}</span>
</div>
</footer>
</body>
{{ if eq .state "out" }}
<script>
const form = document.getElementById("form");
const error = document.getElementById("error");
document.getElementById("anyip").checked = false;
// sent Form via XHR to send data via Header
form.addEventListener("submit", (e) => {
const formData = new FormData(form);
const xhr = new XMLHttpRequest();
xhr.open("POST", window.location, true);
xhr.setRequestHeader("Auth-Form", new URLSearchParams(formData).toString());
xhr.setRequestHeader("X-CSRF-Token", formData.get("csrf"));
// needed for sso cookie
xhr.withCredentials = true;
xhr.onload = (e) => {
if (xhr.status != 200 && (xhr.status < 300 || xhr.status >=400)) {
// Print error message
error.innerHTML = xhr.status + " - Error during login...";
form.reset();
document.getElementById("username").focus();
}
else {
// Refresh
location.reload(true);
}
};
xhr.send(formData);
e.preventDefault();
}, false);
</script>
{{ end }}
</html>