-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
145 lines (103 loc) · 3.83 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div>
<input type="text" placeholder="User Name" class="userName" />
<input type="password" placeholder="Password" class="password" />
<button id="submit">Register</button>
<button id="login">Login</button>
<button id="logout" style="display:none">Logout</button>
</div>
<div class="dashboard">
<ul class="list-data">
</ul>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyDpBdCGR-LPoQgEnMcObbUn5k4WU6pOV-A",
authDomain: "data-scraping-cd97c.firebaseapp.com",
databaseURL: "https://data-scraping-cd97c.firebaseio.com",
projectId: "data-scraping-cd97c",
storageBucket: "data-scraping-cd97c.appspot.com",
messagingSenderId: "494564601702"
};
firebase.initializeApp(config);
//let userId = "WFJxhIpusSPS4ux6uSJvunJ6bWx2";
let ref = firebase.database().ref(`/users/${userId}/${timeStamp}`); // userID
ref.on("child_added", function (snapshot) {
//console.log(snapshot.val());
snapshot.forEach(function (childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val();
var value = childSnapshot.val();
if (value) {
if (value.place) {
$(".list-data").append($(`<li>${value.place}</li>`));
}
if (value.email) {
$(".list-data").append($(`<li>${value.email}</li>`));
}
}
console.log(value);
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
$("#submit").click(function () {
email = $(".userName").val();
password = $(".password").val();
firebase.auth().createUserWithEmailAndPassword(email, password).then(function (user) {
console.log('uid', user.user.uid)
alert("Succes registered account");
let userID = user.user.uid;
$(".password").val("");
$(".userName").val("");
$("#logout").show();
return userID;
}).catch(function (error) {
$(".password").val("");
$(".userName").val("");
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode, errorMessage);
});
})
$("#login").click(function () {
email = $(".userName").val();
password = $(".password").val();
firebase.auth().signInWithEmailAndPassword(email, password).then(function (user) {
console.log('uid', user.user.uid)
console.log(user);
let userID = user.user.uid;
$(".password").val("");
$(".userName").val("");
$("#logout").show();
return userID;
}).catch(function (error) {
$(".password").val("");
$(".userName").val("");
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode, errorMessage);
});
})
$("#logout").click(function () {
firebase.auth().signOut().then(function () {
console.log("Success logout");
$("#logout").hide();
}, function (error) {
console.log(error);
});
})
</script>
</html>