-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.html
265 lines (205 loc) · 10.6 KB
/
register.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> User registration </title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="startingInfoArea" class="container">
<div class="whitespace-separator"></div>
<h1>Participant registration</h1>
<br>
<div class="twelve columns">
<form role="form">
<div class="six columns">
<h3>User information</h3>
<div class="row">
<div class="six columns">
<label for="emailInput">E-mail</label>
<input class="u-full-width" type="email" placeholder="e.g. user@mail.com" id="emailInput" required>
<label for="emailInputDouble">Re-enter E-mail</label>
<input class="u-full-width" type="email" placeholder="e.g. user@mail.com" id="emailInputDouble" required>
<label for="nicknameInput">Participants number (Nickname)</label>
<input class="u-full-width" type="text" placeholder="e.g. GS016 or Colibri" id="nicknameInput" required>
</div>
<div class="six columns">
<label for="passInput">Password</label>
<input class="u-full-width" type="text" placeholder="6 characters minimum" id="passInput" required>
<label for="passInputDouble">Re-enter Password</label>
<input class="u-full-width" type="text" placeholder="6 characters minimum" id="passInputDouble" required>
<label for="firstNameInput">First Name</label>
<input class="u-full-width" type="text" placeholder="e.g. John" id="firstNameInput" required>
</div>
<div class="twelve columns">
<div class="six columns">
<h5>Gender</h5>
<div class="twelve columns">
<form>
<div class="six columns">
<label for="maleRadioBtn">Male</label>
<input type="radio" name="gender" value="male" id="maleRadioBtn" checked>
</div>
<div class="six columns">
<label for="femaleRadioBtn">Female</label>
<input type="radio" name="gender" value="female" id="femaleRadioBtn">
</div>
</form>
</div>
</div>
<div class="six columns">
<label for="ageInput">Age</label>
<input class="u-full-width" type="number" placeholder="e.g. 34" id="ageInput" required min="1">
<label for="stInput">Social Tracker User ID</label>
<input class="u-full-width" type="text" placeholder="Leave empty to disable" id="stInput">
</div>
</div>
</div>
</div>
<div class="six columns">
<div class="row">
<div class="twelve columns">
<div class="whitespace-separator"></div>
<h3>Participant group</h3>
<div class="three columns">
<label for="parkinsonRadioBtn">Parkinson’s Disease</label>
<input type="radio" name="target" value="parkinson" id="parkinsonRadioBtn" checked>
</div>
<div class="three columns">
<label for="nmdRadioBtn">Neuromuscular Disease</label>
<input type="radio" name="target" value="nmd" id="nmdRadioBtn">
</div>
<div class="three columns">
<label for="highTRadioBtn">High Tetraplegia</label>
<input type="radio" name="target" value="tetraplegia" id="highTRadioBtn">
</div>
</div>
<div class="twelve columns">
<h3>Language</h3>
<div class="two columns">
<label for="englishRadioBtn">English</label>
<input type="radio" name="lang" value="english" id="englishRadioBtn" checked>
</div>
<div class="two columns">
<label for="greekRadioBtn">Greek</label>
<input type="radio" name="lang" value="greek" id="greekRadioBtn">
</div>
<div class="two columns">
<label for="hebrewRadioBtn">Hebrew</label>
<input type="radio" name="lang" value="hebrew" id="hebrewRadioBtn">
</div>
</div>
<div class="twelve columns">
<div class="whitespace-separator"></div>
<label>
<input type="checkbox" id="quizCheckbox">
<span class="label-body">Translate Quiz questions to local language</span>
</label>
</div>
</div>
</div>
<button type="submit" class="button-primary button-block" id="registerButton">Register</button>
</form>
</div>
</div>
<div id="endArea" class="container" style="display: none;">
<div class="whitespace-separator"></div>
<h1>Account created!</h1>
<br>
<h3>Please copy your e-mail & password</h3>
<div class="twelve columns">
<div class="row">
<div class="six columns">
<label for="emailReadOnly">Your email</label>
<input class="u-full-width" type="email" id="emailReadOnly" readonly>
</div>
<div class="six columns">
<label for="passReadOnly">Your password</label>
<input class="u-full-width" type="text" id="passReadOnly" readonly>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBMa9gSXsoDo27S7P959QZYf3rJBGDGEIA",
projectId: "mamem-phase2-fall17"
};
config.authDomain = config.projectId + ".firebaseapp.com";
config.databaseURL = "https://" + config.projectId + ".firebaseio.com";
config.storageBucket = config.projectId + ".appspot.com";
firebase.initializeApp(config);
var info = [];
document.getElementById("registerButton").onclick = function() {
console.log(document.getElementById("stInput").value);
info.email = document.getElementById("emailInput").value;
info.password = document.getElementById("passInput").value;
if (info.email !== document.getElementById("emailInputDouble").value){
alert('e-mail address do not match!');
return 0;
}
if (info.password !== document.getElementById("passInputDouble").value){
alert('Passwords do not match!');
return 0;
}
if (info.password.length < 6) {
alert('Password should be longer than 6 chars!');
return 0;
}
info.firstName = document.getElementById("firstNameInput").value;
// Capitalize First letter First name
info.firstName = info.firstName.charAt(0).toUpperCase() + info.firstName.slice(1);
info.nickname = document.getElementById("nicknameInput").value;
info.gender = document.querySelector('input[name="gender"]:checked').value;
info.age = document.getElementById("ageInput").value;
info.stCollectionName = (document.getElementById("stInput").value.length !== 0) ? document.getElementById("stInput").value : null;
info.participantGroup = document.querySelector('input[name="target"]:checked').value;
info.language = document.querySelector('input[name="lang"]:checked').value;
info.translation = document.getElementById("quizCheckbox").checked;
if (!info.email || !info.password || !info.firstName || !info.nickname || !info.age) {
alert('Please fill in all Register fields!');
return 0;
}
var re = /^\w+$/;
if (!re.test(info.password)) {
alert('Your password should contain only latin characters and numbers');
return 0;
}
firebase.auth().createUserWithEmailAndPassword(info.email, info.password).then(function() {
var currentUser = firebase.auth().currentUser;
if (currentUser != null) {
// When saving data on first level, save name too (to be used on scoreboard).
firebase.database().ref('users/' + currentUser.uid + '/userDetails').set({
"nickname": info.nickname,
"firstName": info.firstName,
"gender": info.gender,
"age": info.age,
"lang": info.language,
"quizTranslation": info.translation,
"participantGroup": info.participantGroup,
"socialTracker": !!info.stCollectionName,
"stCollectionName": info.stCollectionName
}, function (error) {
// Account created safely, now hide irrelevant information.
if (!error) {
document.getElementById("emailReadOnly").value = info.email;
document.getElementById("passReadOnly").value = info.password;
document.getElementById("startingInfoArea").style.display = "none";
document.getElementById("endArea").style.display = "block";
}
});
document.getElementById("registerButton").disabled = true;
document.getElementById("registerButton").className += " button-disabled";
} else { alert('Null user'); }
}, function(error) {
alert(error.code);
return error.code;
});
};
</script>
</body>
</html>