-
Notifications
You must be signed in to change notification settings - Fork 0
/
standbyRegistration.html
393 lines (306 loc) · 14.6 KB
/
standbyRegistration.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
<title>SwampHacks Dashboard - Create Account</title>
<meta name="description" content="
SwampHacks is a 36 hour open coding event where students become creators.
In the time allotted, students from around the country come together at the
University of Florida to collaborate on projects, mingle in activities, and
network with sponsors for a fully immersive experience.
"/>
<!-- Stylesheets
================================================== -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!-- <link href="https://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css" rel="stylesheet"> -->
<!-- Favicon
================================================== -->
<link rel="icon" type="image/ico" href="favicon.ico"/>
<!-- Icons & Fonts
================================================== -->
<!-- <link rel="stylesheet" href="css/font-awesome.css"> -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- MLH Badge
================================================== -->
<!-- <a id="mlh-trust-badge" style="display:block;max-width:100px;min-width:60px;position:absolute;right:50px;top:0;width:10%;z-index:0" href="https://mlh.io/seasons/na-2018/events?utm_source=na-2018&utm_medium=TrustBadge&utm_campaign=na-2018&utm_content=white" target="_blank"><img src="https://s3.amazonaws.com/logged-assets/trust-badge/2018/white.svg" alt="Major League Hacking 2017 Hackathon Season" style="width:100%"></a> -->
</head>
<body>
<div id="animationWindow" class="hide">
<div class="loader"></div>
</div>
<div id="layout" class="">
<div id="menuLogin" class="">
<div class="pure-menu-heading" href="#">
<h1 id="mainheader">swamp<b>hacks V</b></h1>
<!-- <img id="logo" class="" src="img/logoblue.svg"></img> -->
</div>
<div class="hide" id="loginStatusTxt">
Please fill in all fields!
</div>
<div class="menu-items-con-login">
<div class="row log" id="regOpen">
<form id="loginForm" class="" autocomplete="off">
<div class="col-md-12 top-margin">
<label class="form-lbl" for="q1" name="">Email</label>
<input class="form-field" id="email" name="q1" type="text" placeholder="" required/>
</div>
<div class="col-md-12 top-margin">
<label class="form-lbl" for="q1" name="">Password</label>
<i class="fa fa-lock pass-visibility" aria-hidden="true" id="pv1" onclick="showPassPressed(pass1, pv1)"></i>
<input class="form-field" id="pass1" name="q1" type="password" placeholder="" required/>
</div>
<div class="col-md-12 top-margin">
<label class="form-lbl" for="q1" name="">Confirm Password</label>
<i class="fa fa-lock pass-visibility" aria-hidden="true" id="pv2" onclick="showPassPressed(pass2, pv2)"></i>
<input class="form-field" id="pass2" name="q1" type="password" placeholder="" required/>
</div>
<div class="col-md-12 top-margin">
<button class="button green" id="createAccountBtn"><a href=""><p class="makeactbtn">Create Account</p></a></button>
</div>
</form>
<div class="margin-buffer">
<div class="col-md-12" style="margin-top: 11px; text-align: center">
<button class="button txtbtnouter" onclick="sendToSignIn()">
<!-- <span class="line"></span> -->
<a href="#" style="display: inline-block"><p class="textbtn">or <b>Sign In</b></p></a>
<!-- <span class="line"></span> -->
</button>
</div>
<div class="col-md-12">
<button class="button google" onclick="googleSignIn()">Google Sign In</button>
</div>
<!-- <div class="col-md-12 top-margin">
<button class="button facebook" onclick="facebookSignIn()">Facebook Sign In</button>
</div> -->
<!-- <div class="col-md-12 descrip-txt login-txt">
Create your account with the email you applied with. This form will not let
you do otherwise!
</div> -->
</div>
</div>
</div>
</div>
<div id="login-side">
<!-- <img class="clock" src="img/clock.jpg"></img> -->
<div class="imgcon">
<img class="colorlogo" src="img/colorlogo.svg"></img>
</div>
<div class="top-blk">
</div>
<div class="bottom-blk">
</div>
</div>
</div>
<!-- <script src="js/menu.js"></script> -->
<script src="js/jquery.js"></script>
<script src="js/classie.js"></script>
<script src='js/bodymovin.min.js'></script>
</body>
<script src="https://www.gstatic.com/firebasejs/3.7.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.7.6/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.7.6/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.7.6/firebase.js"></script>
<script src="https://cdn.firebase.com/js/client/2.3.1/firebase.js"></script>
<script src="firebaseconfig.js"></script>
<script src="facebookconfig.js"></script>
<script>
var ref = firebase.database().ref();
// var usersRef = ref.child("applicants");
var userVerified = false;
var firstClick = true;
var userExists = true;
var repeatCheck = true;
$("form").submit(function() {
repeatCheck = true;
createActBtnClicked();
return false;
});
function createActBtnClicked() {
var email = $("#email").val().trim();
var password = $("#pass1").val();
var confirmPassword = $("#pass2").val();
if (password !== "" && confirmPassword !== "" && email !== "") {
if ((confirmPassword === password)) {
//checkIfUserExists(email);
if (repeatCheck) {
repeatCheck = false;
// Show the loader
$("#animationWindow").removeClass("hide");
$("#animationWindow").addClass("showflex");
setTimeout(function() {
// Hide the loader
$("#animationWindow").removeClass("showflex");
$("#animationWindow").addClass("hide");
//createActBtnClicked();
}, 600);
checkDelay = 0;
} else {
checkDelay = 0;
}
setTimeout(function() {
if (userExists === true) {
var emailSent = false;
// only allow people in standby to register late
const standbyAcceptedRef = ref.child('standbyAccepted');
standbyAcceptedRef.once('value').then(function(snapshot) {
let emails = snapshot.val();
let accepted = false;
for (let key in emails) {
if (emails[key].email == email) {
accepted = true;
// Creating user in firebase
firebase.auth().createUserWithEmailAndPassword(email, password).then(function(user) {
// You can save the user data here.
if (user) {
var userEmail = user.email;
var key = user.uid;
ref.child('users/'+key).set({'email': userEmail, 'applied': false});
localStorage.setItem('loggedInUserKey', key);
} else {
}
firebase.auth().currentUser.sendEmailVerification().then(function() {
// STATUS
$("#loginStatusTxt").text("Verification email sent. Click the link and sign in!");
$("#loginStatusTxt").addClass("show");
this.emailSent = true;
var delay = 2000;
setTimeout(function() {
window.location.href = "login.html";
}, delay);
}.bind(this), function(error) {
if (error !== null) { }
});
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
// Handling different types of errors
if (!this.emailSent) {
if (errorCode.includes("weak-password")) {
// ERROR
$("#loginStatusTxt").text("Password should be at least 6 characters!");
$("#loginStatusTxt").addClass("show");
} else if (errorCode.includes("email-already-in-use")) {
// ERROR
$("#loginStatusTxt").text("Email already in use! Please Login.");
$("#loginStatusTxt").addClass("show");
} else if (errorCode.includes("invalid-email")) {
// ERROR
$("#loginStatusTxt").text("Invalid email!");
$("#loginStatusTxt").addClass("show");
} else {
// ERROR
$("#loginStatusTxt").text("Unknown error making your account. Try again");
$("#loginStatusTxt").addClass("show");
}
}
this.emailSent = false;
}.bind(this));
}
}
if (!accepted) {
// STATUS
$("#loginStatusTxt").text("You do not have permission to register late.");
$("#loginStatusTxt").addClass("show");
}
});
} else {
// ERROR
$("#loginStatusTxt").text("Please use the email you applied with.");
$("#loginStatusTxt").addClass("show");
}
}, checkDelay);
} else {
// ERROR
$("#loginStatusTxt").text("Passwords do not match!");
$("#loginStatusTxt").addClass("show");
}
} else {
// ERROR
$("#loginStatusTxt").text("Please fill in all fields!");
$("#loginStatusTxt").addClass("show");
}
}
function sendToSignIn() {
console.log('called');
window.location.href = 'login.html';
}
function showPassPressed(field, icon) {
if (field.type === "password") {
field.type = "text";
$(icon).removeClass("fa-lock");
$(icon).addClass("fa-unlock-alt");
} else {
field.type = "password";
$(icon).addClass("fa-lock");
$(icon).removeClass("fa-unlock-alt");
}
}
function googleSignIn() {
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('email');
firebase.auth().signInWithPopup(provider).then(function(result) {
if (!result.user) {return;}
// Show the loader
$("#animationWindow").removeClass("hide");
$("#animationWindow").addClass("showflex");
const email = result.user.email;
const emailVerified = result.user.emailVerified;
const userId = result.user.uid;
signInUser(result.user, email, emailVerified, userId);
});
}
function facebookSignIn() {
var provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithPopup(provider)
.then(function(result) {
var token = result.credential.accessToken;
if (!result.user) {return;}
// Show the loader
$("#animationWindow").removeClass("hide");
$("#animationWindow").addClass("showflex");
var user = result.user;
const email = result.user.email;
const emailVerified = result.user.emailVerified;
const userId = result.user.uid;
localStorage.setItem('provider', 'facebook');
signInUser(user, email, emailVerified, userId);
}).catch(function(error) {
console.log(error.code);
console.log(error.message);
});
}
function signInUser(user, email, emailVerified, userId) {
// Save login info in local storage
var userRef = firebase.database().ref("users/"+user.uid);
userRef.once('value').then(function(snapshot) {
localStorage.setItem('loggedInUserKey', user.uid);
if (!snapshot.val()) {
// only allow people in standby to register late
const standbyAcceptedRef = ref.child('standbyAccepted');
standbyAcceptedRef.once('value').then(function(snapshot) {
let emails = snapshot.val();
for (let key in emails) {
if (emails[key].email == email) {
// create user in database
var currentUser = {email: email, applied: false};
ref.child('users/'+userId).set(currentUser);
localStorage.setItem('loggedInUser', JSON.stringify(currentUser));
}
}
});
} else {
localStorage.setItem('loggedInUser', JSON.stringify(snapshot.val()));
}
const delay = 1000;
setTimeout(function() {
// Hide the loader
$("#animationWindow").removeClass("showflex");
$("#animationWindow").addClass("hide");
window.location.href = "index.html";
}, delay);
});
}
</script>
</html>