-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
106 lines (85 loc) · 3.88 KB
/
Copy pathindex.html
File metadata and controls
106 lines (85 loc) · 3.88 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Create Account - Tick Talk</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Google Sign-in -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
<meta name="google-signin-client_id" content="154862558731-9iejifeuec95ronghsg5t71u50203n19.apps.googleusercontent.com">
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
//CHECK IF USER ALREADY IN DB
var userId = firebase.auth().currentUser.uid;
var usernameinputted = "";
var r = firebase.database().ref('/users/' + usernameinputted);
r.on("value", function(snapshot) {
//TODO MAKE SURE that the "on value" event is triggered at the time of this listener being set, and not only when a value changes
if (snapshot.exists()) {
alert("username is already in the database");
} else {
alert("Username is not yet in database. Let's create an account!");
}
}, function(e) {
alert("Unfortunately the client does not have permission to read data :(\nError: " + e);
});
//IF NOT, WRITE NEW USER TO DB
firebase.database().ref('users').child(profile.getName()).set({
username: profile.getName(),
email: profile.getEmail(),
profile_picture: profile.getImageUrl()
});
}
function signOut() {
var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(function () {
console.log('User signed out.');
});
}
function userIsInDB(userToSearch) {
firebase.database().ref('/users/' + userToSearch).on("value", function(snapshot){
if (snapshot.exists()) {
console.log("user " + userToSearch + " IS in database");
return true;
} else {
console.log("user " + userToSearch + " IS NOT in database");
return false;
}
}, function(e) {
alert("Unfortunately the client does not have permission to read data :(\nError: " + e);
});
}
</script>
</head>
<body>
<div class="container-fluid">
<h1>Welcome to Tick Talk - Create Account</h1>
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
<!-- FIREBASE CODE -->
<script src="https://www.gstatic.com/firebasejs/5.2.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBgJzwANAsBxreCUEj14CLZ_05f4zp3pKM", //don't look at this
authDomain: "tick-talk2-1531444556975.firebaseapp.com",
databaseURL: "https://tick-talk2-1531444556975.firebaseio.com",
projectId: "tick-talk2-1531444556975",
storageBucket: "tick-talk2-1531444556975.appspot.com",
messagingSenderId: "154862558731"
};
firebase.initializeApp(config);
</script>
<script>
</script>
</body>
</html>