-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
executable file
·218 lines (197 loc) · 8.19 KB
/
signup.php
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
<!DOCTYPE html>
<html>
<head>
<title>Sign Up</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- jQuery Mobile -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<!--<script src="script.js"></script> -->
<script type="text/javascript">
var signup = function() {
$("#error-message").empty();
var signup_username = $('input#username').val();
var signup_password = $('input#password').val();
var signup_password2 = $('input#password2').val();
var signup_fullname = $('input#fullname').val();
var signup_email = $('input#email').val();
var signup_identity = $('select#identity').val();
var signup_music = $('select#favmusic').val();
var signup_gender = $('select#gender').val();
var signup_zipcode = $('input#zipcode').val();
var signup_latitude = $('input#latitude').val();
var signup_longitude = $('input#longitude').val();
var error_message = "";
if(signup_username == ""){
error_message += "* Please input a username. <br />";
}
if(signup_password == ""){
error_message += "* Please input a password. <br />"
}
if(signup_password != signup_password2){
error_message += "* Confirm password and Password do not match. <br />";
}
if(!isEmail(signup_email)){
error_message += "* Invalid email address. <br />";
}
if(error_message != ""){
$("#error-message").append(error_message);
return false;
}else{
$.ajax({
type: "POST",
url: "checksignup.php",
data:{
username: signup_username,
password: signup_password,
fullname: signup_fullname,
email: signup_email,
identity: signup_identity,
music: signup_music,
gender: signup_gender,
zipcode: signup_zipcode,
latitude: signup_latitude,
longitude: signup_longitude
},
success: function(data) {
if (data == 'success') {
window.location.replace("index.php");
}else if (data == 'registered') {
$("#error-message").append('* Username is already registered. <br />');
}else if(data == 'invalid'){
$("#error-message").append('* Invalid Username or Password. <br />');
}
}
});
}
}
var isEmail = function(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
var getLocation = function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getLatLong);
}else{
alert("Geolocation is not supported by this browser.");
}
}
var getLatLong = function(position) {
$("input#latitude").val(position.coords.latitude);
$("input#longitude").val(position.coords.longitude);
}
var getGeoZipcode = function() {
if(navigator.geolocation) {
var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000);
navigator.geolocation.getCurrentPosition(
function (pos) {
clearTimeout(fallback);
//console.log('pos', pos);
var point = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
new google.maps.Geocoder().geocode({'latLng': point}, function (res, status) {
if(status == google.maps.GeocoderStatus.OK && typeof res[0] !== 'undefined') {
var zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/);
if(zip) {
$("input#zipcode").val(zip[1]);
}else{
fail('Failed to parse');
}
}else{
fail('Failed to reverse');
}
});
}, function(err) {
fail(err.message);
}
);
}else{
$("input#zipcode").val("Geolocation unsupported!");
}
function fail(err) {
console.log('err', err);
$("input#zipcode").val(err);
}
}
var getZip = function(){getGeoZipcode()};
$(window).load(function() {
getZip();
getLocation();
});
</script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<a href="index.html" data-rel="back">Home</a>
<h1>Register Page</h1>
</div>
<div data-role="content">
<!--<form action="" method="post">-->
<div data-role="fieldcontain">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
</div>
<div data-role="fieldcontain">
<label for="password">Password:</label>
<input type="password" name="password" id="password" required>
</div>
<div data-role="fieldcontain">
<label for="password2">Confirm Password:</label>
<input type="password" name="password2" id="password2" required>
</div>
<div data-role="fieldcontain">
<label for="email">Email:</label>
<input type="text" name="email" id="email" required>
</div>
<div data-role="fieldcontain">
<label for="identity">I am a:</label>
<select id="identity" name="identity">
<option value="NULL">Select One</option>
<option>Fan</option>
<option>Artist</option>
<option>Band</option>
<option>Venue</option>
<option>Store/Company</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="fullname">Full Name:</label>
<input type="text" name="fullname" id="fullname">
</div>
<div data-role="fieldcontain">
<label for="gender">Gender:</label>
<select id="gender" name="gener">
<option value="NULL">Select One</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="favmusic">Favorite Music:</label>
<select id="favmusic" name="favmusic">
<option value="NULL">Select One</option>
<option>Pop</option>
<option>Classical</option>
<option>Rock&Roll</option>
<option>Country</option>
<option>Jazz</option>
<option>Blues</option>
<option>Others</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
<input type="hidden" name="latitude" id="latitude">
<input type="hidden" name="longitude" id="longitude">
</div>
<span id="error-message" style="color:red"></span>
<input type="submit" onclick="signup()" value="Register">
<!--</form>-->
</div>
</div>
</body>
</html>