-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.html
executable file
·317 lines (250 loc) · 10.5 KB
/
login.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<!--for Bootstrap modal-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="csshake.min.css">
<link href="style.css" rel="stylesheet" type="text/css">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<meta name="author" content="Cher Huang, Ishani Gupta, Haejin Jo">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Merriweather">
<title>Breathr</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles -->
<style>
body {
padding-top: 54px;
}
@media (min-width: 992px) {
body {
padding-top: 56px;
}
}
</style>
<!--Firebase CSS -->
<link type="text/css" rel="stylesheet" href="https://cdn.firebase.com/libs/firebaseui/2.5.1/firebaseui.css" />
</head>
<body id="loginBody">
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Reset password</h4>
</div>
<div class="modal-body">
<input type="text" id="inputResetEmail" placeholder="Email address" ></input>
</div>
<div class="modal-footer">
<button type="button" id="submitResetEmail" class="btn btn-primary" data-dismiss="modal">Submit Request</button>
</div>
</div>
</div>
</div>
<section class="canvas-wrap">
<div class="canvas-content">
<p class="logoText" style ="font-family:Merriweather script=all rev=2;font-weight: 700;font-color:white; font-style: italic; margin-bottom:0px;">Breathr</p>
<h2 style="font-family:Merriweather script=all rev=2;font-weight: 100;color:white;margin: 0 auto; width: 600px; font-size: 24px; text-align: center;"> Life is more than getting from point A to point B. <br>Always remember to take a breather.</h2>
</div>
<div id="canvas" class="gradient"></div>
</section>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Main library -->
<script src="../js/three.min.js"></script>
<!-- Helpers -->
<script src="../js/projector.js"></script>
<script src="../js/canvas-renderer.js"></script>
<!-- Visualitzation adjustments -->
<script src="../js/3d-lines-animation.js"></script>
<!-- Animated background color -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="../js/color.js"></script>
<div class="container">
<div class="card card-container">
<div class="form-signin">
<input type="email" id="emailInput" class="form-control" placeholder="Email address" required autofocus>
<input type="password" id="passwordInput" class="form-control" placeholder="Password" required>
<!-- <button disabled id="signInButt" class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button> -->
<button disabled id="signInButt" class="btn btn-outline-secondary" type="submit" >Sign in</button>
<p> Don't have an account? <button id="signUpButt" class="btn btn-lg btn-primary btn-block btn-signin">Sign up!</button></p> or<br>
<button id="googleSignInButt" class="btn ">
<span class="fa fa-google-plus" aria-hidden="true"></span> Sign in with Google
</button>
</div><!-- /form -->
<a href="#myModal" data-toggle="modal" class="forgot-password">
Forgot the password?
</a>
</div><!-- /card-container -->
</div><!-- /container -->
</body>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script type="text/javascript">
// Initialize Firebase according to our project specifications
var config = {
apiKey: "AIzaSyD30NRd2YYwkCS25FArj058_oUoXdPYp2I",
authDomain: "safecommutesbhacks2018.firebaseapp.com",
databaseURL: "https://safecommutesbhacks2018.firebaseio.com",
projectId: "safecommutesbhacks2018",
storageBucket: "safecommutesbhacks2018.appspot.com",
messagingSenderId: "178423802061",
};
firebase.initializeApp(config);
/**
* Handles sign in button press
*/
function toggleSignIn() {
if(firebase.auth().currentUser) { //if someone is signed in already
document.getElementById('signInButt').disabled=false;
firebase.auth().signOut(); // they're clicking to sign out
} else { // somebody wants to sign in
var email = document.getElementById('emailInput').value;
var password = document.getElementById('passwordInput').value;
if(email.length < 4) {
alert('Please enter an email address.');
return;
}
if (password.length < 4) {
alert('Please enter a password');
return;
}
firebase.auth().signInWithEmailAndPassword(email, password)
.catch(function(error) {
//Handle Errors here
var errorCode = error.code;
var errorMessage = error.message;
if(errorCode == 'auth/wrong-password') {
alert('Wrong password.');
} else {
alert(errorMessage);
}
console.log(error);
document.getElementById('signInButt').disabled = false;
});
}
// END authwithemail
}
// CALLED WHEN USER PRESSES SIGN IN WITH GOOGLE
function googleSignIn() {
if(!firebase.auth().currentUser) { // if not signed in
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithRedirect(provider);
} else{
document.getElementById('googleSignInButt').disabled=true;
}
}
/*
* Handles sign up button press
*/
function handleSignUp() {
console.log("signing up a user")
var email = document.getElementById('emailInput').value;
var password = document.getElementById('passwordInput').value;
if(email.length < 4) {
alert('Please enter a valid email address');
return;
}
if(password.length < 4) {
alert('Please enter a password');
return;
}
firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(user) {
console.log(user);
})
.catch(function(error) {
//Handle errors here.
var errorCode= error.code;
var errorMessage = error.message;
if(errorCode == 'auth/weak-password') {
alert('The password is too weak.');
} else {
alert(errorMessage);
}
console.log(error);
});
// END createwithemail
}
function sendPasswordReset() {
var email = document.getElementById('inputResetEmail').value;
firebase.auth().sendPasswordResetEmail(email)
.then(function() {
alert('Password Reset Email Sent!');
}).catch(function(error) {
//Handle errors here
var errorCode = error.code;
var errorMessage = error.message;
if(errorCode == 'auth/invalid-email') {
alert(errorMessage);
console.log("hi: ", email);
} else if (errorCode == 'auth/user-not-found') {
alert(errorMessage);
}
console.log(error);
});
//END sendpasswordemail
}
/**
* handles setting up UI event listeners and registering Firebase auth listeners:
* - firebase.auth().onAuthStateChanged listerer called when user is signed in or out, and THAT is where we update the UI
*/
function initApp() {
//Listening for auth state changes
firebase.auth().onAuthStateChanged(user => {
if(user) { // User is signed in
// var displayName = user.displayName;
// var email = user.email;
// var emailVerified = user.emailVerified;
var uid = user.uid;
window.location = 'index.html'; //after successful login, user redirects here
document.getElementById('quickstart-sign-in-status').textContent = 'Signed in!';
document.getElementById('quickstart-account-details').textContent = JSON.stringify(user, null, ' ');
document.getElementById('signInButt').textContent = 'Sign out';
document.getElementById('signUpButt').disabled=true;
document.getElementById('signInButt').disabled=false;
} else { //User is signed out
document.getElementById('signInButt').textContent = 'Sign in';
document.getElementById('signInButt').disabled=false;
document.getElementById('signUpButt').disabled=false;
document.getElementById('googleSignInButt').disabled=false;
}
});
// [END authstatelistener]
document.getElementById('signInButt').addEventListener('click', toggleSignIn);
document.getElementById('signUpButt').addEventListener('click', handleSignUp);
document.getElementById('googleSignInButt').addEventListener('click', googleSignIn);
document.getElementById('submitResetEmail').addEventListener('click',sendPasswordReset);
}
window.onload = function() {
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// ...
}
// The signed-in user info.
var user = result.user;
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
initApp();
};
</script>
</html>