-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreg.html
183 lines (160 loc) · 4.83 KB
/
reg.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>OpenTeens</title>
<link rel="stylesheet" href="css/login.css" />
<style>
#loading {
display: none;
text-align: center;
margin-top: 20px;
}
#loading img {
width: 50px;
height: 50px;
}
html {
background-color: #252526;
}
</style>
</head>
<body>
<div id="welcome">
<div id="terminal">
<h2 id="slogan" ia-group="welcome"></h2>
<div id="typing-welcome" ia-group="welcome"
active="typing_effect($('#typing-welcome'), 'Greetings from the Community! \n Let us know who you are ...')">
</div>
<div ia-group="welcome" active="$('#login-username').focus()">
<br>
<span class="formtitle">Create a username (6-20 chars, MUST only contains letters (lower case), digists and '_')</span>
<br>
<span class="inputhint">→</span><input id="login-username" class="login" autofill="false">
<button id="username-submit" class="login" disabled
onclick="if (!this.disabled) interactive('welcome')">Continue</button>
</div>
<div ia-group="welcome" active="$('#login-pwd').focus()">
<br>
<span class="formtitle">Create a password</span>
<br>
<span class="inputhint">→</span><input id="login-pwd" class="login" type="password">
<button id="password-submit" class="login" disabled
onclick="if (!this.disabled) performLogin()">Continue</button>
</div>
<div id="loading">
<style>
#loading-ani {
display: block;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #fff;
animation: loading 1s infinite;
}
@keyframes loading {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
opacity: 0;
}
}
</style>
<center><span id="loading-ani"></span></center>
<p>Registing ...</p>
</div>
</div>
</div>
</body>
<script src="js/sel.js"></script>
<script>
function interactive(group, index) {
if (index == undefined) {
var items = $$(`[ia-group="${group}"]`);
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.style.display != "block") {
item.style.display = "block";
eval(item.getAttribute("active"));
return;
}
}
} else {
// specified item
var item = $$(`[ia-group="${group}"]`)[index];
item.style.display = "block";
eval(item.getAttribute("active"));
}
}
function typing_effect(div, text) {
function helper(i) {
if (i >= text.length) {
interactive(div.getAttribute('ia-group'));
return "Completed.";
}
if (text[i - 1] == ' ')
div.innerText += ' ' + text[i];
else
div.innerText += text[i];
setTimeout(helper, 30, i + 1);
}
helper(0);
}
$("#login-username").addEventListener("input", function () {
if (this.value.length >= 6 && this.value.length <= 20) {
$("#username-submit").disabled = false;
} else {
$("#username-submit").disabled = true;
}
})
$("#login-pwd").addEventListener("input", function () {
if (this.value.length >= 6 && this.value.length <= 20) {
$("#password-submit").disabled = false;
} else {
$("#password-submit").disabled = true;
}
})
function performLogin() {
// Disable form elements
document.getElementById("login-username").disabled = true;
document.getElementById("login-pwd").disabled = true;
document.getElementById("password-submit").disabled = true;
// get username and password
var username = document.getElementById("login-username").value;
var password = document.getElementById("login-pwd").value;
// Send login request
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.openteens.org/auth/register", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var response = JSON.parse(xhr.responseText);
if (response.code == 0) {
// Login successful
document.cookie = `ot_auth_token=${response.token}; expires=${new Date(Date.now() + 60 * 24 * 60 * 60 * 1000).toUTCString()}; domain=openteens.org; SameSite=None; Secure;`;
document.cookie = `ot_username=${username}; expires=${new Date(Date.now() + 60 * 24 * 60 * 60 * 1000).toUTCString()}; domain=openteens.org;`;
window.location.href = "/";
} else {
// Login failed
alert("login failed: " + response.msg);
document.getElementById("login-username").disabled = false;
document.getElementById("login-pwd").disabled = false;
document.getElementById("password-submit").disabled = false;
}
}
}
xhr.send(JSON.stringify({
"username": username,
"password": password
}));
// Show loading animation
document.getElementById("loading").style.display = "block";
}
window.onload = function () {
interactive("welcome", 0);
typing_effect($("#slogan"), "Empower Teenagers Through Open Source.");
}
</script>
</html>