-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (77 loc) · 3.52 KB
/
main.js
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
var firebaseConfig = {
apiKey: "AIzaSyB2kMCF_wglD3NPBDjSl6phkYrorRI1LgE",
authDomain: "minecraft-world-community.firebaseapp.com",
databaseURL: "https://minecraft-world-community-default-rtdb.firebaseio.com",
projectId: "minecraft-world-community",
storageBucket: "minecraft-world-community.appspot.com",
messagingSenderId: "79164899563",
appId: "1:79164899563:web:36388146fef46073c63eae"
};
firebase.initializeApp(firebaseConfig);
function loged() {
user = document.getElementById("username").value;
password = document.getElementById("userpassword").value;
if (user != "" && password != "") {
var userref = firebase.database().ref("/users/" + user + "/status");
var passref = firebase.database().ref("/users/" + user + "/password");
var isUserCreated;
var isJoining = false;
userref.on("value", data => {
isUserCreated = data.val();
if (!isJoining) {
isJoining = true;
if (isUserCreated == "online") {
passref.on("value", data => {
canPass = data.val();
if (canPass == password) {
localStorage.setItem("user", user);
localStorage.setItem("pass", password);
window.location = "MinecraftRooms.html";
} else {
document.getElementById("error").innerHTML = "Incorrect Password";
document.getElementById("userpassword").style.borderColor = "red";
}
})
} else {
document.getElementById("error").innerHTML = "Incorrect Username";
document.getElementById("username").style.borderColor = "red";
}
}
});
} else {
document.getElementById("error").innerHTML = "All the inputs need a value";
document.getElementById("username").style.borderColor = "yellow";
document.getElementById("userpassword").style.borderColor = "yellow";
}
}
function createAccount() {
user = document.getElementById("username").value;
password = document.getElementById("userpassword").value;
if (user != "" && password != "") {
var userref = firebase.database().ref("/users/" + user + "/status");
var isUserCreated;
var isJoining = false;
userref.on("value", data => {
isUserCreated = data.val();
if (!isJoining) {
isJoining = true;
if (isUserCreated == null) {
firebase.database().ref("/users/").child(user).update({
password: password,
status: "online",
userImg: "creeper",
followers: 0
});
document.getElementById("error").innerHTML = "Account Sucessfuly Created";
} else {
document.getElementById("error").innerHTML = "This username already exists";
document.getElementById("username").style.borderColor = "red";
}
}
});
} else {
document.getElementById("error").innerHTML = "All the inputs need a value";
document.getElementById("username").style.borderColor = "yellow";
document.getElementById("userpassword").style.borderColor = "yellow";
}
}