-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.htm
207 lines (196 loc) · 7.52 KB
/
apply.htm
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apply - BAYMS.Web</title>
<meta name="google-signin-client_id" content="293667705573-956voda6p3vco06c8jik51umdql2hmgf.apps.googleusercontent.com">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="author" content="Kevin Zhang">
<link rel="icon" href="./favicon.ico">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Raleway:400,300,600">
<link rel="stylesheet" href="./css/normalize.css" />
<link rel="stylesheet" href="./css/skeleton.css" />
<script src="//apis.google.com/js/platform.js"></script>
<script src="./js/jquery.js"></script>
<style>
body {
background-color: whitesmoke;
}
.progress {
display: none;
color: #33C3F0;
}
input[type=checkbox] {
/* Double-sized Checkboxes */
-ms-transform: scale(2); /* IE */
-moz-transform: scale(2); /* FF */
-webkit-transform: scale(2); /* Safari and Chrome */
-o-transform: scale(2); /* Opera */
padding: 10px;
}
.error {
display: none;
color: white;
background-color: #FF6347;
padding: 6px 10px;
border-radius: 4px;
margin-bottom: 1.5rem;
}
.error a {
color: lightblue;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="one-half column" style="margin-top: 5%">
<h1><i class="progress fa fa-circle-o-notch fa-spin"></i> BAYMS.Web</h1>
<form id="apply">
<div class="row">
<div class="columns">
<label for="user_name">Username</label>
<input id="user_name" class="u-full-width" type="text"
placeholder="e.g. firstname.lastname">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="user_pass">Password</label>
<input id="user_pass" class="u-full-width" type="password">
</div>
<div class="six columns">
<label for="confirm_user_pass">Confirm Password</label>
<input id="confirm_user_pass" class="u-full-width" type="password">
</div>
</div>
<div class="row">
<div class="columns">
<label for='ReCaptcha' id='demo'></label>
<input id="ReCaptcha" class="u-full-width" placeholder="So fresh so clean, class of..." type="text">
</div>
</div>
<div class="row">
<div class="columns">
<input type="checkbox" id="terms"> I have read and agreed to the <a href="ToS.htm" target="_blank">Terms of Service</a> <br>
</div>
</div>
<div class="row">
<div class="columns">
<div id="security-error" class="error">
<i class="fa fa-exclamation-triangle"></i> Password must be at least 6 characters long.
</div>
<div id="password-error" class="error">
<i class="fa fa-exclamation-triangle"></i> Sorry, your passwords do not match.
</div>
<div id="apply-error" class="error">
<i class="fa fa-exclamation-triangle"></i> Sorry, that username is already taken.
</div>
<div id="recaptcha-error" class="error">
<i class="fa fa-exclamation-triangle"></i> Sorry, the confirmation is incorrect.
</div>
<div id="terms-error" class="error">
<i class="fa fa-exclamation-triangle"></i> You must agree to the Terms of Service.
</div>
</div>
</div>
<input class="button-primary" type="submit" id ="apply" value="Apply">
<p>Already a member? <a href="login.htm">Sign in here</a>!</p>
</form>
<hr/>
<div class="row">
<div class="columns">
<h5>Or, <u><b>apply</b></u> using Google Sign-In:</h5>
<p>By applying using google, you agree to follow the Terms of Service above.</p>
<div id="google-error" class="error">
<i class="fa fa-exclamation-triangle"></i> You already have an account! Please
try signing in at: <a href="login.htm">http://dev.bayms.org/login.htm</a>
</div>
<div class="g-signin2" data-onsuccess="googleApply"></div>
<br style="clear:both;"/>
</div>
</div>
</div>
</div>
</div>
<script>
// Redirect
if (sessionStorage.getItem('user_name') || sessionStorage.getItem('google_token'))
window.location.href = "index.htm";
// ReCaptcha
var z = (function(){
var x = Math.floor((Math.random() * 10) + 1);
var y = Math.floor((Math.random() * 10) + 1);
var forNow = 2018;
//$('#demo').text("What is " + x + " + " + y + " = ?" );
//return x + y;
$('#demo').text("Confirmation code:" );
return forNow;
})();
// Traditional Authetnication
$("#apply").submit(function(event) {
event.preventDefault();
$('.error').hide();
if ($('#user_pass').val().length < 6)
return $('#security-error').show();
if ($('#user_pass').val() != $('#confirm_user_pass').val())
return $('#password-error').show();
if (parseInt($('#ReCaptcha').val()) != z)
return $('#recaptcha-error').show();
if (!$("#terms").is(':checked'))
return $('#terms-error').show();
$('.progress').show();
tryApply($('#user_name').val(), $('#user_pass').val(), function(data) {
$('.progress').hide();
if (data) {
window.location.href = "index.htm";
} else {
$('.error').hide();
$('#apply-error').show();
}
});
});
function tryApply(user_name, user_pass, callback) {
$.ajax({
method: "POST",
url: "./api/api.php?x=apply",
dataType: "json",
data: { "user_name": user_name, "user_pass": user_pass}
}).done(function(data) {
if (data) {
sessionStorage.setItem('user_type', 0);
sessionStorage.setItem('user_name', user_name);
sessionStorage.setItem('user_pass', user_pass);
callback(data);
} else {
callback(false);
}
}).error(function(err) {
callback(false)
});
}
// Google Authentication
function googleApply(googleUser) {
if (!sessionStorage.getItem('google_token'))
gapi.auth2.getAuthInstance().signOut();
var google_token = googleUser.getAuthResponse().id_token;
$.ajax({
method: "POST",
url: "./api/api.php?x=google_apply",
dataType: "json",
data: {"google_token": google_token}
}).done(function(data) {
if (data) {
sessionStorage.setItem('user_type', 0);
sessionStorage.setItem('google_token', google_token);
window.location.href = "index.htm";
} else {
$('#google-error').show();
}
}).error(function(err) {
$('#google-error').show();
});
}
</script>
</body>
</html>