forked from anuragverma108/SwapReads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylogin.html
231 lines (210 loc) · 8.68 KB
/
mylogin.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- Bootstrap theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="./assets/css/MenuClick.css">
<title>How to create Firebase login and register?</title>
<link rel="stylesheet" href="./assets/css/login.css" />
<style>
.remember-me-label {
font-size: 14px;
display: inline-flex;
align-items: center;
}
.remember-me-label input {
margin-right: 8px;
/* Adjusted margin */
margin-top: 1px;
/* Added margin-top for better alignment */
}
.main {
display: flex;
justify-content: space-between; /* Ensures that the two sections are aligned properly */
align-items: flex-start; /* Align items at the top */
}
.login, .register {
flex: 1; /* Make both sections take equal width */
margin: 10px; /* Add some space between the forms */
padding: 20px;
border: 1px solid #ddd; /* Optional: Add borders to separate forms visually */
}
.input {
width: 100%; /* Ensure the input fields take up full width of their containers */
margin: 10px 0; /* Add consistent margin between inputs */
padding: 10px;
box-sizing: border-box; /* Make sure padding does not affect width */
}
button {
width: 100%; /* Make buttons full width */
padding: 10px;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="navbar nav_activated">
<div class="navbar-header">
<a href="index.html">
<img class="close-icon" src="./assets/images/close.png" alt="Close">
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" id="logout" style="display: none">Log Out</a></li>
</ul>
</div>
</div>
<div class="note">
<h1>
Hey !! Welcome to SwapReads. Please get yourself Registered or verify your credentials to get started.
</h1>
</div>
<br />
<div class="container">
<div class="main">
<input type="checkbox" id="chk" aria-hidden="true" />
<div class="login">
<form class="form">
<label for="chk" aria-hidden="true">Log in</label>
<input class="input" type="email" name="email" id="login_email" placeholder="Email" required="" />
<input class="input" type="password" name="pswd" id="login_password" placeholder="Password"
required="" />
<label class="remember-me-label">
<input type="checkbox" id="rememberMe"> Remember Me
</label>
<button type="button" name="Login" id="login">Log in</button>
</form>
</div>
<div class="register">
<form class="form">
<label for="chk" aria-hidden="true">Register</label>
<input class="input" type="email" name="email" id="email" placeholder="Email" required="" />
<input class="input" type="password" name="pswd" id="password" placeholder="Password" required="" />
<button type="button" name="register" id="register">Register</button>
</form>
</div>
</div>
</div>
<hr>
<footer class="footer">
<div class="container">
<div class="footer-bottom">
<p class="copyright">
© <span id="copyright-year"></span> All right reserved. Made with ❤ by Guardian Hackers.
</p>
</div>
</div>
</footer>
<script>document.getElementById("copyright-year").textContent = new Date().getFullYear();</script>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.1/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/10.8.1/firebase-analytics.js";
import { getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut } from "https://www.gstatic.com/firebasejs/10.8.1/firebase-auth.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCu2WXknNce_49J5BLuR1DyHm319hu6dWc",
authDomain: "login-13127.firebaseapp.com",
projectId: "login-13127",
storageBucket: "login-13127.appspot.com",
messagingSenderId: "151656578300",
appId: "1:151656578300:web:c67208ab6ec437c844ab79",
measurementId: "G-L3PPD58MZ8"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const auth = getAuth();
// Remember Me functionality
window.onload = function () {
if (localStorage.getItem('rememberMe') === 'true') {
document.getElementById('login_email').value = localStorage.getItem('email');
document.getElementById('login_password').value = localStorage.getItem('password');
document.getElementById('rememberMe').checked = true;
}
};
document.getElementById("register").addEventListener("click", function () {
let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
// For new registration
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
console.log(user);
alert("Registration successful!");
document.getElementById("email").value = "";
document.getElementById("password").value = "";
})
.catch((error) => {
const errorMessage = error.message;
console.log(errorMessage);
alert(errorMessage);
});
});
document.getElementById("login").addEventListener("click", function () {
let email = document.getElementById("login_email").value;
let password = document.getElementById("login_password").value;
let rememberMe = document.getElementById("rememberMe").checked;
signInWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Signed in
if (rememberMe) {
localStorage.setItem('email', email);
localStorage.setItem('password', password);
localStorage.setItem('rememberMe', true);
} else {
localStorage.removeItem('email');
localStorage.removeItem('password');
localStorage.removeItem('rememberMe');
}
window.location.href = "index.html";
document.getElementById("logout").style.display = "block";
})
.catch((error) => {
const errorMessage = error.message;
console.log(errorMessage);
alert(errorMessage);
});
});
document.getElementById("logout").addEventListener("click", function () {
signOut(auth)
.then(() => {
console.log("Sign-out successful.");
})
.catch((error) => {
console.log("An error happened.");
});
});
</script>
<script>
const navbar=document.querySelector('.navbar'),
NavButton=document.querySelector('.nav-toggle-btn'),
open=document.querySelector('.open'),
close=document.querySelector('.close');
let count=0
NavButton.addEventListener('click',()=>{
if(count===0){
navbar.classList.remove('nav_activated')
open.classList.add('close')
close.classList.add('open')
open.classList.remove('open')
close.classList.remove('close')
count++
}
else{
navbar.classList.add('nav_activated')
open.classList.add('open')
close.classList.add('close')
open.classList.remove('close')
close.classList.remove('open')
count=0
}
})
</script>
</body>
</html>