joermd commited on
Commit
36cd920
·
verified ·
1 Parent(s): 36cff15

Update login.html

Browse files
Files changed (1) hide show
  1. login.html +164 -9
login.html CHANGED
@@ -153,7 +153,12 @@
153
  margin-top: 10px;
154
  }
155
 
156
- button:hover {
 
 
 
 
 
157
  transform: translateY(-2px);
158
  box-shadow: 0 8px 25px rgba(218, 165, 32, 0.4);
159
  }
@@ -179,7 +184,7 @@
179
  }
180
 
181
  .message {
182
- padding: 10px;
183
  margin-top: 15px;
184
  border-radius: 8px;
185
  text-align: center;
@@ -188,16 +193,40 @@
188
 
189
  .message.show {
190
  display: block;
 
191
  }
192
 
193
  .message.error {
194
  background-color: #ffebee;
195
  color: #d32f2f;
 
196
  }
197
 
198
  .message.success {
199
  background-color: #e8f5e9;
200
  color: #388e3c;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
 
203
  @media (max-width: 520px) {
@@ -213,12 +242,18 @@
213
  h2 {
214
  font-size: 26px;
215
  }
 
 
 
 
 
 
216
  }
217
  </style>
218
  </head>
219
  <body>
220
  <div class="logo-container">
221
- <img src="https://ufastpro.com/wp-content/uploads/2024/11/تصميم-بدون-عنوان-3.png" alt="Logo" class="logo" style="width: 100%; height: 100%; object-fit: contain; border-radius: 50%;">
222
  </div>
223
 
224
  <div class="container">
@@ -237,7 +272,10 @@
237
  <input type="password" id="loginPassword" required placeholder="أدخل كلمة المرور">
238
  </div>
239
 
240
- <button type="submit">تسجيل الدخول</button>
 
 
 
241
  <div id="loginMessage" class="message"></div>
242
  </form>
243
 
@@ -282,7 +320,10 @@
282
  <input type="password" id="registerPassword" required placeholder="8 أحرف على الأقل" minlength="8">
283
  </div>
284
 
285
- <button type="submit">إنشاء الحساب</button>
 
 
 
286
  <div id="registerMessage" class="message"></div>
287
  </form>
288
 
@@ -298,9 +339,18 @@
298
  <script>
299
  const API_URL = 'https://j8fp9mu44k547j-7777.proxy.runpod.net/proxy/6500/api';
300
 
 
 
 
 
 
 
 
 
301
  function toggleForm() {
302
  document.querySelector('.forms-container').classList.toggle('flipped');
303
  clearMessages();
 
304
  }
305
 
306
  function clearMessages() {
@@ -316,7 +366,30 @@
316
  element.className = `message ${isError ? 'error' : 'success'} show`;
317
  }
318
 
319
- function handleLogin(event) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
320
  event.preventDefault();
321
 
322
  const email = document.getElementById('loginEmail').value;
@@ -331,12 +404,45 @@
331
  showMessage('loginMessage', 'الرجاء إدخال بريد إلكتروني صحيح', true);
332
  return false;
333
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334
 
335
- showMessage('loginMessage', 'جاري تسجيل الدخول...', false);
336
  return false;
337
  }
338
 
339
- function handleRegister(event) {
340
  event.preventDefault();
341
 
342
  const officeName = document.getElementById('officeName').value;
@@ -367,13 +473,62 @@
367
  return false;
368
  }
369
 
370
- showMessage('registerMessage', 'جاري إنشاء الحساب...', false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  return false;
372
  }
373
 
374
  function isValidEmail(email) {
375
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
376
  }
 
 
 
 
 
 
 
 
 
 
 
 
377
  </script>
378
  </body>
379
  </html>
 
153
  margin-top: 10px;
154
  }
155
 
156
+ button:disabled {
157
+ opacity: 0.7;
158
+ cursor: not-allowed;
159
+ }
160
+
161
+ button:hover:not(:disabled) {
162
  transform: translateY(-2px);
163
  box-shadow: 0 8px 25px rgba(218, 165, 32, 0.4);
164
  }
 
184
  }
185
 
186
  .message {
187
+ padding: 12px;
188
  margin-top: 15px;
189
  border-radius: 8px;
190
  text-align: center;
 
193
 
194
  .message.show {
195
  display: block;
196
+ animation: fadeIn 0.3s ease-in;
197
  }
198
 
199
  .message.error {
200
  background-color: #ffebee;
201
  color: #d32f2f;
202
+ border: 1px solid #ffcdd2;
203
  }
204
 
205
  .message.success {
206
  background-color: #e8f5e9;
207
  color: #388e3c;
208
+ border: 1px solid #c8e6c9;
209
+ }
210
+
211
+ .loading-spinner {
212
+ display: inline-block;
213
+ width: 20px;
214
+ height: 20px;
215
+ border: 3px solid rgba(255, 255, 255, 0.3);
216
+ border-radius: 50%;
217
+ border-top-color: #fff;
218
+ animation: spin 1s ease-in-out infinite;
219
+ margin-left: 10px;
220
+ vertical-align: middle;
221
+ }
222
+
223
+ @keyframes spin {
224
+ to { transform: rotate(360deg); }
225
+ }
226
+
227
+ @keyframes fadeIn {
228
+ from { opacity: 0; transform: translateY(-10px); }
229
+ to { opacity: 1; transform: translateY(0); }
230
  }
231
 
232
  @media (max-width: 520px) {
 
242
  h2 {
243
  font-size: 26px;
244
  }
245
+
246
+ .logo-container {
247
+ width: 120px;
248
+ height: 120px;
249
+ top: 20px;
250
+ }
251
  }
252
  </style>
253
  </head>
254
  <body>
255
  <div class="logo-container">
256
+ <img src="https://ufastpro.com/wp-content/uploads/2024/11/تصميم-بدون-عنوان-3.png" alt="Logo" style="width: 100%; height: 100%; object-fit: contain; border-radius: 50%;">
257
  </div>
258
 
259
  <div class="container">
 
272
  <input type="password" id="loginPassword" required placeholder="أدخل كلمة المرور">
273
  </div>
274
 
275
+ <button type="submit" id="loginButton">
276
+ تسجيل الدخول
277
+ <span class="loading-spinner" style="display: none;"></span>
278
+ </button>
279
  <div id="loginMessage" class="message"></div>
280
  </form>
281
 
 
320
  <input type="password" id="registerPassword" required placeholder="8 أحرف على الأقل" minlength="8">
321
  </div>
322
 
323
+ <button type="submit" id="registerButton">
324
+ إنشاء الحساب
325
+ <span class="loading-spinner" style="display: none;"></span>
326
+ </button>
327
  <div id="registerMessage" class="message"></div>
328
  </form>
329
 
 
339
  <script>
340
  const API_URL = 'https://j8fp9mu44k547j-7777.proxy.runpod.net/proxy/6500/api';
341
 
342
+ // التحقق من وجود token عند تحميل الصفحة
343
+ document.addEventListener('DOMContentLoaded', function() {
344
+ const token = localStorage.getItem('userToken');
345
+ if (token) {
346
+ window.location.href = '/dashboard'; // توجيه المستخدم للوحة التحكم إذا كان مسجل دخول
347
+ }
348
+ });
349
+
350
  function toggleForm() {
351
  document.querySelector('.forms-container').classList.toggle('flipped');
352
  clearMessages();
353
+ enableButtons();
354
  }
355
 
356
  function clearMessages() {
 
366
  element.className = `message ${isError ? 'error' : 'success'} show`;
367
  }
368
 
369
+ function toggleLoadingState(formId, isLoading) {
370
+ const form = document.getElementById(formId);
371
+ const button = form.querySelector('button[type="submit"]');
372
+ const spinner = button.querySelector('.loading-spinner');
373
+
374
+ button.disabled = isLoading;
375
+ spinner.style.display = isLoading ? 'inline-block' : 'none';
376
+
377
+ // تعطيل جميع المدخلات أثناء التحميل
378
+ form.querySelectorAll('input, select').forEach(input => {
379
+ input.disabled = isLoading;
380
+ });
381
+ }
382
+
383
+ function enableButtons() {
384
+ document.querySelectorAll('button').forEach(button => {
385
+ button.disabled = false;
386
+ });
387
+ document.querySelectorAll('.loading-spinner').forEach(spinner => {
388
+ spinner.style.display = 'none';
389
+ });
390
+ }
391
+
392
+ async function handleLogin(event) {
393
  event.preventDefault();
394
 
395
  const email = document.getElementById('loginEmail').value;
 
404
  showMessage('loginMessage', 'الرجاء إدخال بريد إلكتروني صحيح', true);
405
  return false;
406
  }
407
+ try {
408
+ toggleLoadingState('loginForm', true);
409
+ showMessage('loginMessage', 'جاري تسجيل الدخول...', false);
410
+
411
+ const response = await fetch(`${API_URL}/login`, {
412
+ method: 'POST',
413
+ headers: {
414
+ 'Content-Type': 'application/json',
415
+ 'Accept': 'application/json'
416
+ },
417
+ body: JSON.stringify({ email, password })
418
+ });
419
+
420
+ const data = await response.json();
421
+
422
+ if (response.ok) {
423
+ // تخزين token في localStorage
424
+ localStorage.setItem('userToken', data.token);
425
+ localStorage.setItem('userData', JSON.stringify(data.user));
426
+
427
+ showMessage('loginMessage', 'تم تسجيل الدخول بنجاح! جاري التحويل...', false);
428
+
429
+ // التوجيه إلى لوحة التحكم بعد ثانية
430
+ setTimeout(() => {
431
+ window.location.href = '/dashboard';
432
+ }, 1000);
433
+ } else {
434
+ throw new Error(data.message || 'فشل تسجيل الدخول');
435
+ }
436
+ } catch (error) {
437
+ showMessage('loginMessage', error.message || 'حدث خطأ أثناء تسجيل الدخول. الرجاء المحاولة مرة أخرى', true);
438
+ } finally {
439
+ toggleLoadingState('loginForm', false);
440
+ }
441
 
 
442
  return false;
443
  }
444
 
445
+ async function handleRegister(event) {
446
  event.preventDefault();
447
 
448
  const officeName = document.getElementById('officeName').value;
 
473
  return false;
474
  }
475
 
476
+ try {
477
+ toggleLoadingState('registerForm', true);
478
+ showMessage('registerMessage', 'جاري إنشاء الحساب...', false);
479
+
480
+ const response = await fetch(`${API_URL}/register`, {
481
+ method: 'POST',
482
+ headers: {
483
+ 'Content-Type': 'application/json',
484
+ 'Accept': 'application/json'
485
+ },
486
+ body: JSON.stringify({
487
+ officeName,
488
+ userRole,
489
+ phone,
490
+ email,
491
+ password
492
+ })
493
+ });
494
+
495
+ const data = await response.json();
496
+
497
+ if (response.ok) {
498
+ showMessage('registerMessage', 'تم إنشاء الحساب بنجاح! يمكنك الآن تسجيل الدخول', false);
499
+
500
+ // العودة إلى نموذج تسجيل الدخول بعد ثانيتين
501
+ setTimeout(() => {
502
+ toggleForm();
503
+ document.getElementById('loginEmail').value = email;
504
+ }, 2000);
505
+ } else {
506
+ throw new Error(data.message || 'فشل إنشاء الحساب');
507
+ }
508
+ } catch (error) {
509
+ showMessage('registerMessage', error.message || 'حدث خطأ أثناء إنشاء الحساب. الرجاء المحاولة مرة أخرى', true);
510
+ } finally {
511
+ toggleLoadingState('registerForm', false);
512
+ }
513
+
514
  return false;
515
  }
516
 
517
  function isValidEmail(email) {
518
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
519
  }
520
+
521
+ // معالجة الأخطاء العامة
522
+ window.onerror = function(msg, url, lineNo, columnNo, error) {
523
+ console.error('Error: ' + msg + '\nURL: ' + url + '\nLine: ' + lineNo + '\nColumn: ' + columnNo + '\nError object: ' + JSON.stringify(error));
524
+ return false;
525
+ };
526
+
527
+ // معالجة أخطاء الشبكة
528
+ window.addEventListener('offline', function(e) {
529
+ showMessage('loginMessage', 'لا يوجد اتصال بالإنترنت', true);
530
+ showMessage('registerMessage', 'لا يوجد اتصال بالإنترنت', true);
531
+ });
532
  </script>
533
  </body>
534
  </html>