-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
162 lines (139 loc) · 6.19 KB
/
index.html
File metadata and controls
162 lines (139 loc) · 6.19 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Journaly</title>
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=mail" />
</head>
<body>
<div class="login-box" id="login-box">
<form id="loginForm">
<div class="login-header">
<h2>Sign In</h2>
</div>
<div class="input-box">
<span class="icon"></span>
<input type="email" id="email" required>
<label>Email</label>
</div>
<div class="input-box">
<span class="icon"></span>
<input type="password" id="password" required>
<label>Password</label>
</div>
<div class="remember-forgot">
<label><input type="checkbox">Remember me</label>
<a href="./passwordreset.html">Forgot Password?</a>
</div>
<button type="submit" id="signInBtn">Sign In</button>
<button type="button" id="googleSignInBtn">Sign In with Google</button>
<div class="register-link">
<p>Don't have an account? <a href="./register.html">Register</a></p>
</div>
<div id="errorMessage" style="color: red; margin-top: 10px; display: none;"></div>
</form>
</div>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
import { getAuth, signInWithEmailAndPassword, GoogleAuthProvider, signInWithPopup } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
const firebaseConfig = {
apiKey: "AIzaSyAWmlQgPu34uIDOsBBy4J3bdPB4QFue1iI",
authDomain: "journal-d2fcd.firebaseapp.com",
projectId: "journal-d2fcd",
storageBucket: "journal-d2fcd.firebasestorage.app",
messagingSenderId: "279588365736",
appId: "1:279588365736:web:47c252930b9fad19fd299d",
measurementId: "G-6QHND3BWFR"
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
function init() {
const loginForm = document.getElementById('loginForm');
const emailInput = document.getElementById('email');
const passwordInput = document.getElementById('password');
const errorDiv = document.getElementById('errorMessage');
const googleSignInBtn = document.getElementById('googleSignInBtn');
function showError(message) {
errorDiv.textContent = message;
errorDiv.style.display = 'block';
}
function hideError() {
errorDiv.style.display = 'none';
}
// Email/Password Login
loginForm.addEventListener('submit', async (e) => {
e.preventDefault();
hideError();
const email = emailInput.value.trim();
const password = passwordInput.value;
if (!email || !password) {
showError('Please enter both email and password');
return;
}
try {
await signInWithEmailAndPassword(auth, email, password);
window.location.href = './welcome.html';
} catch (error) {
let errorMessage = '';
switch (error.code) {
case 'auth/invalid-email':
errorMessage = 'Invalid email format';
break;
case 'auth/user-not-found':
errorMessage = 'No account found with this email';
break;
case 'auth/wrong-password':
errorMessage = 'Incorrect password';
break;
case 'auth/invalid-credential':
errorMessage = 'Invalid email or password';
break;
case 'auth/too-many-requests':
errorMessage = 'Too many failed attempts. Please try again later';
break;
default:
errorMessage = 'Login failed. Please try again';
}
showError(errorMessage);
}
});
// Google Sign-In
googleSignInBtn.addEventListener('click', async (e) => {
e.preventDefault();
hideError();
try {
const provider = new GoogleAuthProvider();
await signInWithPopup(auth, provider);
window.location.href = './welcome.html';
} catch (error) {
let errorMessage = '';
switch (error.code) {
case 'auth/popup-closed-by-user':
errorMessage = 'Sign-in cancelled';
break;
case 'auth/popup-blocked':
errorMessage = 'Please allow popups for this site';
break;
case 'auth/unauthorized-domain':
errorMessage = 'Domain not authorized in Firebase Console';
break;
default:
errorMessage = 'Google sign-in failed';
}
showError(errorMessage);
}
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(init, 100);
});
} else {
setTimeout(init, 100);
}
</script>
</body>
</html>