-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
211 lines (185 loc) · 9.46 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
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
<html>
<head>
<title>GameParlour</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="hero" style="background-image: url('images/background.png');">
<div class="form-box">
<div class="button-box">
<div id="btn"></div>
<button type="button" class="toggle-btn" onclick="login()">Login</button>
<button type="button" class="toggle-btn" onclick="register()">Register</button>
</div>
<div class="social-icons">
<img src="images/fb.png">
<img src="images/tw.png">
<img id="googleImage" src="images/gp.png">
</div>
<div id="login" class="input-group">
<input type="email" class="input-field" id="loginEmail" placeholder="Email" required>
<input type="password" class="input-field" id="loginPassword" placeholder="Password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<button id="loginBtn" class="submit-btn">Login</button>
</div>
<div id="register" class="input-group">
<input type="text" class="input-field" id="fullName" placeholder="Full Name" required/>
<br/> <br/>
<label style="color: white;" for="gender">Gender: </label>
<select id="gender" name="gender" class="gender" required>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select> <br/> <br/>
<label style="color: white;" for="DOB">DOB: </label>
<input type="date" id="newDOB" placeholder="Date of Birth" required/>
<input type="email" class="input-field" id="newEmail" placeholder="Email" required/>
<input type="tel" class="input-field" id="phoneNo" placeholder="Phone Number" required/>
<input type="password" class="input-field" id="newPassword" placeholder="Password" required/>
<input type="checkbox" class="check-box" required><span>I agree to all the terms & conditions.</span>
<button type="submit" id="registerBtn" class="submit-btn">Register</button>
</div>
</div>
</div>
<script>
var x = document.getElementById("login");
var y = document.getElementById("register");
var z = document.getElementById("btn");
function register() {
x.style.left = "-400px";
y.style.left = "50px";
z.style.left = "110px";
}
function login() {
x.style.left = "50px";
y.style.left = "450px";
z.style.left = "0";
}
</script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-analytics.js";
import { getAuth, GoogleAuthProvider, signInWithPopup, createUserWithEmailAndPassword, signInWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-auth.js";
import { getDatabase, set, ref, update } from "https://www.gstatic.com/firebasejs/9.8.1/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
apiKey: "AIzaSyC7FwfSWzYnpD8t4FAxuNs6Sj2ejHA4zAk",
authDomain: "gameparlour-a3458.firebaseapp.com",
projectId: "gameparlour-a3458",
storageBucket: "gameparlour-a3458.appspot.com",
messagingSenderId: "420512068803",
appId: "1:420512068803:web:4aeab218cdc6e833245e76",
measurementId: "G-5C7MLF0CH8"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const analytics = getAnalytics(app);
const provider = new GoogleAuthProvider(app);
const database = getDatabase(app);
//Register User (SignUp)
registerBtn.addEventListener('click',(e)=>{
var fullName = document.getElementById('fullName').value;
var gender = document.getElementById('gender').selectedOptions[0].value;
var DOB = document.getElementById('newDOB').value;
var email = document.getElementById('newEmail').value;
var phoneNo = document.getElementById('phoneNo').value;
var password = document.getElementById('newPassword').value;
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
set(ref(database, 'users/' + user.uid), {
Full_Name: fullName,
gender: gender,
DOB: DOB,
Email: email,
Phone_No: phoneNo,
Password: password
})
.then(() => {
// Data saved successfully!
//alert("Welcome!" + Full_Name + "!");
localStorage.setItem("fullName", fullName);
localStorage.setItem("gender", gender);
localStorage.setItem("DOB", DOB);
localStorage.setItem("email", email);
localStorage.setItem("phoneNo", phoneNo);
loginSuccess();
})
.catch((error) => {
// The write failed...
alert(error.message);
});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
alert(errorMessage);
});
});
//Login User (login)
loginBtn.addEventListener('click',(e)=>{
var email = document.getElementById('loginEmail').value;
var password = document.getElementById('loginPassword').value;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
// ...
var lgDate = new Date();
update(ref(database, 'users/' + user.uid), {
Last_Login: lgDate
})
.then(() => {
// Data saved successfully!
localStorage.setItem("email", email);
loginSuccess();
alert("Welcome");
})
.catch((error) => {
// The write failed...
alert(error.message);
});
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
alert(errorMessage);
});
});
//SignIn with Google
googleImage.addEventListener('click',(e)=> {
signInWithPopup(auth, provider)
.then((result) => {
// This gives you a Google Access Token. You can use it to access the Google API.
const credential = GoogleAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
// The signed-in user info.
const user = result.user;
alert("Welcome" + user.displayName);
loginSuccess();
// ...
}).catch((error) => {
// Handle Errors here.
const errorCode = error.code;
const errorMessage = error.message;
// The email of the user's account used.
const email = error.email;
// The AuthCredential type that was used.
const credential = GoogleAuthProvider.credentialFromError(error);
// ...
alert(errorMessage);
});
});
function loginSuccess() {
window.location.href = "https://gameparlourhome.web.app/";
}
</script>
</body>
</html>