Alinabil1 commited on
Commit
d6d15aa
·
1 Parent(s): 8070696

fix: update login.html with working API connection

Browse files
Files changed (1) hide show
  1. frontend/login.html +17 -26
frontend/login.html CHANGED
@@ -5,7 +5,7 @@
5
  <meta name="viewport" content="width=device-width,initial-scale=1"/>
6
  <title>تسجيل الدخول — منصة محرك</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
8
- <link rel="stylesheet" href="/theme.css?v=moharek2025"/>
9
  <style>
10
  body { display:flex; align-items:center; justify-content:center; min-height:100vh; position:relative; }
11
  .login-container { width:100%; max-width:520px; padding:20px; position:relative; z-index:10; }
@@ -95,14 +95,11 @@
95
  </div>
96
 
97
  <script>
98
- // Use relative API path for Hugging Face Spaces compatibility
99
  const API = window.location.origin + '/api';
100
-
101
- const params = new URLSearchParams(window.location.search);
102
- const mode = params.get('mode') || 'login';
103
- if (mode === 'signup') {
104
- switchTab('register');
105
- }
106
 
107
  function switchTab(tab) {
108
  const tabs = document.querySelectorAll('.tab');
@@ -147,6 +144,9 @@
147
 
148
  btn.disabled = true;
149
  btn.textContent = 'جارٍ تسجيل الدخول...';
 
 
 
150
 
151
  try {
152
  const res = await fetch(API + '/users/login', {
@@ -154,29 +154,24 @@
154
  headers: { 'Content-Type': 'application/json' },
155
  body: JSON.stringify({ email, password })
156
  });
157
-
 
158
  const data = await res.json();
 
159
 
160
  if (data.ok && data.token) {
161
- console.log('Login successful, token:', data.token.substring(0, 20) + '...');
162
  localStorage.setItem('token', data.token);
163
  localStorage.setItem('user', JSON.stringify(data.user || {}));
164
- console.log('Token stored in localStorage');
165
-
166
  showSuccess('تم تسجيل الدخول بنجاح! جاري التحويل...');
167
-
168
- setTimeout(() => {
169
- console.log('Redirecting to portal...');
170
- window.location.href = '/app/portal.html';
171
- }, 1500);
172
  } else {
173
  showError(data.error || 'فشل تسجيل الدخول');
174
  btn.disabled = false;
175
  btn.textContent = 'تسجيل الدخول';
176
  }
177
  } catch (err) {
178
- console.error('Login error:', err);
179
- showError('خطأ في الاتصال بالخادم');
180
  btn.disabled = false;
181
  btn.textContent = 'تسجيل الدخول';
182
  }
@@ -216,20 +211,16 @@
216
  if (data.ok && data.token) {
217
  localStorage.setItem('token', data.token);
218
  localStorage.setItem('user', JSON.stringify(data.user || {}));
219
-
220
  showSuccess('تم إنشاء الحساب بنجاح! جاري التحويل...');
221
-
222
- setTimeout(() => {
223
- window.location.href = '/app/portal.html';
224
- }, 1500);
225
  } else {
226
  showError(data.error || 'فشل إنشاء الحساب');
227
  btn.disabled = false;
228
  btn.textContent = 'إنشاء حساب';
229
  }
230
  } catch (err) {
231
- console.error('Register error:', err);
232
- showError('خطأ في الاتصال بالخادم');
233
  btn.disabled = false;
234
  btn.textContent = 'إنشاء حساب';
235
  }
 
5
  <meta name="viewport" content="width=device-width,initial-scale=1"/>
6
  <title>تسجيل الدخول — منصة محرك</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="/theme.css?v=2025"/>
9
  <style>
10
  body { display:flex; align-items:center; justify-content:center; min-height:100vh; position:relative; }
11
  .login-container { width:100%; max-width:520px; padding:20px; position:relative; z-index:10; }
 
95
  </div>
96
 
97
  <script>
 
98
  const API = window.location.origin + '/api';
99
+
100
+ console.log('=== Moharek Login v2025 ===');
101
+ console.log('Origin:', window.location.origin);
102
+ console.log('API URL:', API);
 
 
103
 
104
  function switchTab(tab) {
105
  const tabs = document.querySelectorAll('.tab');
 
144
 
145
  btn.disabled = true;
146
  btn.textContent = 'جارٍ تسجيل الدخول...';
147
+
148
+ console.log('Login attempt:', email);
149
+ console.log('Endpoint:', API + '/users/login');
150
 
151
  try {
152
  const res = await fetch(API + '/users/login', {
 
154
  headers: { 'Content-Type': 'application/json' },
155
  body: JSON.stringify({ email, password })
156
  });
157
+
158
+ console.log('Status:', res.status);
159
  const data = await res.json();
160
+ console.log('Data:', data);
161
 
162
  if (data.ok && data.token) {
 
163
  localStorage.setItem('token', data.token);
164
  localStorage.setItem('user', JSON.stringify(data.user || {}));
 
 
165
  showSuccess('تم تسجيل الدخول بنجاح! جاري التحويل...');
166
+ setTimeout(() => window.location.href = '/app/portal.html', 1500);
 
 
 
 
167
  } else {
168
  showError(data.error || 'فشل تسجيل الدخول');
169
  btn.disabled = false;
170
  btn.textContent = 'تسجيل الدخول';
171
  }
172
  } catch (err) {
173
+ console.error('Error:', err);
174
+ showError('خطأ في الاتصال: ' + err.message);
175
  btn.disabled = false;
176
  btn.textContent = 'تسجيل الدخول';
177
  }
 
211
  if (data.ok && data.token) {
212
  localStorage.setItem('token', data.token);
213
  localStorage.setItem('user', JSON.stringify(data.user || {}));
 
214
  showSuccess('تم إنشاء الحساب بنجاح! جاري التحويل...');
215
+ setTimeout(() => window.location.href = '/app/portal.html', 1500);
 
 
 
216
  } else {
217
  showError(data.error || 'فشل إنشاء الحساب');
218
  btn.disabled = false;
219
  btn.textContent = 'إنشاء حساب';
220
  }
221
  } catch (err) {
222
+ console.error('Error:', err);
223
+ showError('خطأ في الاتصال: ' + err.message);
224
  btn.disabled = false;
225
  btn.textContent = 'إنشاء حساب';
226
  }