-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpinsignup.js
63 lines (58 loc) · 1.73 KB
/
pinsignup.js
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
/*
PIN Signup JS
Frank Giddens
November 4, 2018
*/
"use strict";
let socket = io.connect();
let fields = ["userName", "password", "email", "firstName", "lastName", "nickname", "age", "gender", "address", "address2", "city", "state", "zipCode", "shareLocation", "pushNotifications", "allowMicrophone", "legalDisclaimer"];
let required = [true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, true];
document.getElementById("submit").addEventListener("click", function(){
let acceptInfo = true;
let info = {};
for(let i = 0; i < fields.length; i++){
console.log(fields[i]);
if(i < fields.length - 4){
if(required[i] && document.getElementById(fields[i]).value == ""){
acceptInfo = false;
}
info[fields[i]] = document.getElementById(fields[i]).value;
}
else{
if(document.getElementById(fields[i]).checked == false && i == (fields.length - 1)){
acceptInfo = false;
}
else{
info[fields[i]] = document.getElementById(fields[i]).checked;
}
}
}
if(info.userName.length < 8 || info.userName.length > 24){
acceptInfo = false;
alert("Invalid Username: Username must have between 8 and 24 characters");
}
if(info.password.length < 8 || info.password.length > 24){
acceptInfo = false;
alert("Invalid Password: Password must have between 8 and 24 characters");
}
if(info.email.indexOf("@") < 1){
acceptInfo = false;
window.alert("Invalid Email Address");
}
if(!acceptInfo){
alert("Incomplete Form");
}
else{
socket.emit("signupPIN", info);
}
});
socket.on("signupReceived", function(data){
if(data.success){
localStorage.type = "PIN";
localStorage.user = data.user;
location = "pindashboard.html";
}
else{
alert("Username Taken");
}
});