-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp.txt
125 lines (103 loc) · 4.87 KB
/
temp.txt
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
//Hide the Content
document.getElementById('UserDetails').style.display="none";
document.getElementById('confirmation').style.display="none";
document.getElementById('logout').style.display="none";
document.getElementById('updateData').style.display="none";
// Initialize Firebase
var config = {
***
};
firebase.initializeApp(config);
//Call Events
document.getElementById('login').addEventListener('click',loginUser);
document.getElementById('submit').addEventListener('click',addData);
document.getElementById('logout').addEventListener('click',logoutUser);
//Google Sign In Provider
var provider = new firebase.auth.GoogleAuthProvider();
//Call Functions
function loginUser(){
firebase.auth().signInWithPopup(provider).then(function(result) {
var token = result.credential.accessToken;
var user = result.user;
console.log(user);
}).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
var email = error.email;
var credential = error.credential;
});
}
function logoutUser(){
firebase.auth().signOut().then(function() {
// Sign-out successful.
document.getElementById('logout').style.display="none";
document.getElementById('login').style.display="block";
document.getElementById('UserDetails').style.display="none";
document.getElementById('updateData').style.display="none";
}).catch(function(error) {
// An error happened.
});
}
var email;
var uid;
console.log("User Email "+email);
function addData(){
if(email){
var name=document.getElementById('name').value;
var mobile=document.getElementById('mobile').value;
var organization=document.getElementById('organization').value;
var designation=document.getElementById('designation').value;
var why=document.getElementById('why').value;
var data={
name:name,
email:email,
mobile:mobile,
org:organization,
designation:designation,
why:why,
timestamp:Date(),
uid:uid
}
firebase.database().ref('IOAttendees/'+uid).set(data).then(()=>{
alert("User SuccessFully Registered");
document.getElementById('UserInput').innerHTML="Thank you Filling this Form";
document.getElementById('confirmation').style.display="block";
})
console.log(email);
}
else{
alert("you need to Login with Google");
//document.getElementById('userDetailSection').innerHTML="Thank you Filling this Form";
}
}
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
var displayName = user.displayName;
email = user.email;
var emailVerified = user.emailVerified;
var photoURL = user.photoURL;
var isAnonymous = user.isAnonymous;
uid = user.uid;
var providerData = user.providerData;
console.log(email);
document.getElementById('SignInMsg').innerHTML="<b style='color:blue'>"+displayName+"</b> Successfully Logged In with : <b style='color:blue'>"+email+"</b>";
document.getElementById('logout').style.display="block";
document.getElementById('login').style.display="none";
firebase.database().ref('IOAttendees/'+uid).once('value',(snap)=>{
if(snap.val()){
document.getElementById('UserDetails').style.display="none";
document.getElementById('updateData').style.display="block";
}
else{
document.getElementById('UserDetails').style.display="block";
}
})
// ...
} else {
// User is signed out.
// ...
document.getElementById('UserDetails').style.display="none";
console.log("err");
document.getElementById('SignInMsg').innerHTML="You need to sign in with a Google account or a Gmail address to register for this event.";
}
});