-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.html
More file actions
281 lines (247 loc) · 10.1 KB
/
auth.html
File metadata and controls
281 lines (247 loc) · 10.1 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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#1a1a2e">
<title>Connexion - Time Progress App</title>
<link rel="stylesheet" href="styles.css">
<style>
.auth-container {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.auth-box {
background: var(--surface);
border-radius: 20px;
padding: 40px;
max-width: 400px;
width: 100%;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.auth-box h1 {
text-align: center;
margin-bottom: 10px;
color: var(--text-primary);
}
.auth-box p {
text-align: center;
color: var(--text-secondary);
margin-bottom: 30px;
}
.auth-tabs {
display: flex;
gap: 10px;
margin-bottom: 30px;
}
.auth-tab {
flex: 1;
padding: 12px;
background: transparent;
border: 2px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
color: var(--text-secondary);
cursor: pointer;
font-weight: 600;
transition: all 0.3s;
}
.auth-tab.active {
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
border-color: var(--primary-color);
color: white;
}
.auth-form {
display: none;
}
.auth-form.active {
display: block;
}
.google-btn {
width: 100%;
padding: 12px;
background: white;
color: #333;
border: 2px solid #ddd;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
margin-top: 20px;
transition: all 0.3s;
}
.google-btn:hover {
border-color: var(--primary-color);
transform: translateY(-2px);
}
.divider {
text-align: center;
margin: 20px 0;
color: var(--text-secondary);
position: relative;
}
.divider::before,
.divider::after {
content: '';
position: absolute;
top: 50%;
width: 40%;
height: 1px;
background: rgba(255, 255, 255, 0.1);
}
.divider::before {
left: 0;
}
.divider::after {
right: 0;
}
.error-message {
background: rgba(214, 48, 49, 0.2);
color: var(--danger);
padding: 12px;
border-radius: 10px;
margin-bottom: 20px;
display: none;
}
.error-message.show {
display: block;
}
</style>
</head>
<body>
<div class="auth-container">
<div class="auth-box">
<h1>Time Progress</h1>
<p>Gérez vos périodes de temps</p>
<div class="auth-tabs">
<button class="auth-tab active" data-tab="login">Connexion</button>
<button class="auth-tab" data-tab="signup">Inscription</button>
</div>
<div class="error-message" id="errorMessage"></div>
<!-- Formulaire de connexion -->
<form class="auth-form active" id="loginForm">
<div class="form-group">
<label for="loginEmail">Email</label>
<input type="email" id="loginEmail" required placeholder="votre@email.com">
</div>
<div class="form-group">
<label for="loginPassword">Mot de passe</label>
<input type="password" id="loginPassword" required placeholder="••••••••">
</div>
<button type="submit" class="btn-submit" style="width: 100%; margin-top: 20px;">
Se connecter
</button>
</form>
<!-- Formulaire d'inscription -->
<form class="auth-form" id="signupForm">
<div class="form-group">
<label for="signupEmail">Email</label>
<input type="email" id="signupEmail" required placeholder="votre@email.com">
</div>
<div class="form-group">
<label for="signupPassword">Mot de passe</label>
<input type="password" id="signupPassword" required placeholder="••••••••" minlength="6">
</div>
<div class="form-group">
<label for="signupPasswordConfirm">Confirmer le mot de passe</label>
<input type="password" id="signupPasswordConfirm" required placeholder="••••••••" minlength="6">
</div>
<button type="submit" class="btn-submit" style="width: 100%; margin-top: 20px;">
Créer un compte
</button>
</form>
<div class="divider">ou</div>
<button class="google-btn" id="googleBtn">
<svg width="20" height="20" viewBox="0 0 24 24">
<path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
<path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
<path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
<path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
</svg>
Continuer avec Google
</button>
</div>
</div>
<script type="module">
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js';
import { getAuth, signInWithEmailAndPassword, createUserWithEmailAndPassword, signInWithPopup, GoogleAuthProvider } from 'https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js';
// Charger la configuration
const script = document.createElement('script');
script.src = 'firebase-config.js';
document.head.appendChild(script);
script.onload = () => {
// Initialiser Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const googleProvider = new GoogleAuthProvider();
// Gestion des onglets
const tabs = document.querySelectorAll('.auth-tab');
const forms = document.querySelectorAll('.auth-form');
const errorMessage = document.getElementById('errorMessage');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
tabs.forEach(t => t.classList.remove('active'));
forms.forEach(f => f.classList.remove('active'));
tab.classList.add('active');
document.getElementById(tab.dataset.tab + 'Form').classList.add('active');
errorMessage.classList.remove('show');
});
});
// Fonction pour afficher les erreurs
function showError(message) {
errorMessage.textContent = message;
errorMessage.classList.add('show');
}
// Connexion
document.getElementById('loginForm').addEventListener('submit', async (e) => {
e.preventDefault();
const email = document.getElementById('loginEmail').value;
const password = document.getElementById('loginPassword').value;
try {
await signInWithEmailAndPassword(auth, email, password);
window.location.href = 'index.html';
} catch (error) {
showError('Email ou mot de passe incorrect');
}
});
// Inscription
document.getElementById('signupForm').addEventListener('submit', async (e) => {
e.preventDefault();
const email = document.getElementById('signupEmail').value;
const password = document.getElementById('signupPassword').value;
const passwordConfirm = document.getElementById('signupPasswordConfirm').value;
if (password !== passwordConfirm) {
showError('Les mots de passe ne correspondent pas');
return;
}
try {
await createUserWithEmailAndPassword(auth, email, password);
window.location.href = 'index.html';
} catch (error) {
if (error.code === 'auth/email-already-in-use') {
showError('Cet email est déjà utilisé');
} else if (error.code === 'auth/weak-password') {
showError('Le mot de passe doit contenir au moins 6 caractères');
} else {
showError('Erreur lors de la création du compte');
}
}
});
// Connexion avec Google
document.getElementById('googleBtn').addEventListener('click', async () => {
try {
await signInWithPopup(auth, googleProvider);
window.location.href = 'index.html';
} catch (error) {
showError('Erreur lors de la connexion avec Google');
}
});
};
</script>
</body>
</html>