joermd commited on
Commit
edb4daf
·
verified ·
1 Parent(s): 87874cf

Update login.html

Browse files
Files changed (1) hide show
  1. login.html +151 -126
login.html CHANGED
@@ -1,177 +1,202 @@
1
  <!DOCTYPE html>
2
  <html lang="ar" dir="rtl">
3
- <!-- Previous head and style sections remain exactly the same -->
4
  <head>
5
- <!-- Previous head content remains the same -->
6
  <meta charset="UTF-8">
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <title>نظام المصادقة الذكي</title>
9
- <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap" rel="stylesheet">
10
  <style>
11
- /* Previous styles remain exactly the same */
12
- /* ... */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </style>
14
  </head>
15
  <body>
16
- <!-- Previous HTML structure remains exactly the same until the script section -->
17
- <div class="background-animation">
18
- <div class="circle circle-1"></div>
19
- <div class="circle circle-2"></div>
20
- </div>
21
-
22
  <div class="container">
23
- <div class="auth-card">
24
- <div class="card-header">
25
- <h1>نظام المصادقة</h1>
26
- <p>مرحباً بك في نظام المصادقة الذكي</p>
 
27
  </div>
28
-
29
- <div class="tabs">
30
- <button class="tab active" onclick="switchTab('login')">تسجيل الدخول</button>
31
- <button class="tab" onclick="switchTab('register')">حساب جديد</button>
32
  </div>
 
 
 
 
 
33
 
34
- <form id="loginForm" style="display: block;">
35
- <div id="loginMessage"></div>
36
- <div class="form-group">
37
- <label class="form-label">اسم المستخدم</label>
38
- <input type="text" class="form-input" name="username" placeholder="أدخل اسم المستخدم" required>
39
- </div>
40
- <div class="form-group">
41
- <label class="form-label">كلمة المرور</label>
42
- <input type="password" class="form-input" name="password" placeholder="أدخل كلمة المرور" required>
43
- </div>
44
- <button type="submit" class="submit-btn">تسجيل الدخول</button>
45
- </form>
46
-
47
- <form id="registerForm" style="display: none;">
48
- <div id="registerMessage"></div>
49
- <div class="form-group">
50
- <label class="form-label">اسم المستخدم</label>
51
- <input type="text" class="form-input" name="username" placeholder="أدخل اسم المستخدم" required>
52
- </div>
53
- <div class="form-group">
54
- <label class="form-label">البريد الإلكتروني</label>
55
- <input type="email" class="form-input" name="email" placeholder="أدخل البريد الإلكتروني" required>
56
- </div>
57
- <div class="form-group">
58
- <label class="form-label">الاسم الكامل</label>
59
- <input type="text" class="form-input" name="fullName" placeholder="أدخل اسمك الكامل">
60
- </div>
61
- <div class="form-group">
62
- <label class="form-label">كلمة المرور</label>
63
- <input type="password" class="form-input" name="password" placeholder="أدخل كلمة المرور" required>
64
- </div>
65
- <button type="submit" class="submit-btn">إنشاء حساب</button>
66
- </form>
67
  </div>
68
  </div>
69
 
70
  <script>
71
- // API Base URL
72
- const API_URL = 'https://j8fp9mu44k547j-7777.proxy.runpod.net/proxy/6000';
73
 
74
- function switchTab(tab) {
75
- const loginForm = document.getElementById('loginForm');
76
- const registerForm = document.getElementById('registerForm');
77
- const tabs = document.querySelectorAll('.tab');
78
-
79
- tabs.forEach(t => t.classList.remove('active'));
80
- if (tab === 'login') {
81
- loginForm.style.display = 'block';
82
- registerForm.style.display = 'none';
83
- tabs[0].classList.add('active');
84
- } else {
85
- loginForm.style.display = 'none';
86
- registerForm.style.display = 'block';
87
- tabs[1].classList.add('active');
88
- }
89
  }
90
 
91
- document.getElementById('loginForm').addEventListener('submit', async (e) => {
92
- e.preventDefault();
93
- const form = e.target;
94
- const messageBox = document.getElementById('loginMessage');
95
 
96
  try {
97
- form.classList.add('loading');
98
-
99
- const formData = new FormData();
100
- formData.append('username', form.username.value);
101
- formData.append('password', form.password.value);
102
-
103
- const response = await fetch(`${API_URL}/token`, {
104
  method: 'POST',
105
- body: formData
 
 
 
106
  });
107
 
108
  const data = await response.json();
109
 
110
  if (response.ok) {
111
- messageBox.innerHTML = `
112
- <div class="message success-message">
113
- تم تسجيل الدخول بنجاح
114
- </div>
115
- `;
116
- localStorage.setItem('token', data.access_token);
117
- // يمكنك إضافة إعادة توجيه هنا إذا كنت ترغب
118
  } else {
119
- throw new Error(data.detail || 'خطأ في تسجيل الدخول');
120
  }
121
  } catch (error) {
122
- messageBox.innerHTML = `
123
- <div class="message error-message">
124
- ${error.message === 'Failed to fetch' ? 'فشل الاتصال بالخادم' : error.message}
125
- </div>
126
- `;
127
- } finally {
128
- form.classList.remove('loading');
129
  }
130
- });
131
 
132
- document.getElementById('registerForm').addEventListener('submit', async (e) => {
133
- e.preventDefault();
134
- const form = e.target;
135
- const messageBox = document.getElementById('registerMessage');
136
 
137
  try {
138
- form.classList.add('loading');
139
-
140
  const response = await fetch(`${API_URL}/register`, {
141
  method: 'POST',
142
  headers: {
143
- 'Content-Type': 'application/json',
144
  },
145
- body: JSON.stringify({
146
- username: form.username.value,
147
- email: form.email.value,
148
- full_name: form.fullName.value,
149
- password: form.password.value
150
- })
151
  });
152
 
153
  const data = await response.json();
154
 
155
  if (response.ok) {
156
- messageBox.innerHTML = `
157
- <div class="message success-message">
158
- تم إنشاء الحساب بنجاح
159
- </div>
160
- `;
161
- setTimeout(() => switchTab('login'), 2000);
162
  } else {
163
- throw new Error(data.detail || 'خطأ في إنشاء الحساب');
164
  }
165
  } catch (error) {
166
- messageBox.innerHTML = `
167
- <div class="message error-message">
168
- ${error.message === 'Failed to fetch' ? 'فشل الاتصال بالخادم' : error.message}
169
- </div>
170
- `;
171
- } finally {
172
- form.classList.remove('loading');
173
  }
174
- });
175
  </script>
176
  </body>
177
  </html>
 
1
  <!DOCTYPE html>
2
  <html lang="ar" dir="rtl">
 
3
  <head>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>نظام تسجيل الدخول</title>
 
7
  <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ font-family: 'Cairo', sans-serif;
13
+ }
14
+
15
+ body {
16
+ background: linear-gradient(120deg, #2980b9, #8e44ad);
17
+ height: 100vh;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ }
22
+
23
+ .container {
24
+ width: 100%;
25
+ max-width: 400px;
26
+ padding: 20px;
27
+ }
28
+
29
+ .form-box {
30
+ background: white;
31
+ padding: 40px;
32
+ border-radius: 10px;
33
+ box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
34
+ display: none;
35
+ }
36
+
37
+ .form-box.active {
38
+ display: block;
39
+ }
40
+
41
+ h2 {
42
+ text-align: center;
43
+ color: #2c3e50;
44
+ margin-bottom: 30px;
45
+ }
46
+
47
+ .input-group {
48
+ margin-bottom: 20px;
49
+ }
50
+
51
+ input {
52
+ width: 100%;
53
+ padding: 12px;
54
+ border: 1px solid #ddd;
55
+ border-radius: 5px;
56
+ font-size: 16px;
57
+ }
58
+
59
+ button {
60
+ width: 100%;
61
+ padding: 12px;
62
+ background: #3498db;
63
+ border: none;
64
+ border-radius: 5px;
65
+ color: white;
66
+ font-size: 16px;
67
+ cursor: pointer;
68
+ transition: background 0.3s;
69
+ }
70
+
71
+ button:hover {
72
+ background: #2980b9;
73
+ }
74
+
75
+ .switch-form {
76
+ text-align: center;
77
+ margin-top: 20px;
78
+ color: white;
79
+ cursor: pointer;
80
+ }
81
+
82
+ .error-message {
83
+ color: #e74c3c;
84
+ margin-top: 10px;
85
+ text-align: center;
86
+ }
87
+
88
+ .success-message {
89
+ color: #2ecc71;
90
+ margin-top: 10px;
91
+ text-align: center;
92
+ }
93
  </style>
94
  </head>
95
  <body>
 
 
 
 
 
 
96
  <div class="container">
97
+ <!-- نموذج تسجيل الدخول -->
98
+ <div id="loginForm" class="form-box active">
99
+ <h2>تسجيل الدخول</h2>
100
+ <div class="input-group">
101
+ <input type="text" id="loginUsername" placeholder="اسم المستخدم">
102
  </div>
103
+ <div class="input-group">
104
+ <input type="password" id="loginPassword" placeholder="كلمة المرور">
 
 
105
  </div>
106
+ <button onclick="login()">دخول</button>
107
+ <div id="loginError" class="error-message"></div>
108
+ <div id="loginSuccess" class="success-message"></div>
109
+ <div class="switch-form" onclick="toggleForms()">إنشاء حساب جديد</div>
110
+ </div>
111
 
112
+ <!-- نموذج إنشاء حساب -->
113
+ <div id="registerForm" class="form-box">
114
+ <h2>إنشاء حساب جديد</h2>
115
+ <div class="input-group">
116
+ <input type="text" id="registerUsername" placeholder="اسم المستخدم">
117
+ </div>
118
+ <div class="input-group">
119
+ <input type="password" id="registerPassword" placeholder="كلمة المرور">
120
+ </div>
121
+ <button onclick="register()">إنشاء حساب</button>
122
+ <div id="registerError" class="error-message"></div>
123
+ <div id="registerSuccess" class="success-message"></div>
124
+ <div class="switch-form" onclick="toggleForms()">تسجيل الدخول</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  </div>
126
  </div>
127
 
128
  <script>
129
+ const API_URL = 'https://j8fp9mu44k547j-7777.proxy.runpod.net/proxy/6500/api'; // قم بتغيير هذا إلى عنوان RunPod الخاص بك
 
130
 
131
+ function toggleForms() {
132
+ document.getElementById('loginForm').classList.toggle('active');
133
+ document.getElementById('registerForm').classList.toggle('active');
134
+ // مسح رسائل الخطأ والنجاح
135
+ clearMessages();
136
+ }
137
+
138
+ function clearMessages() {
139
+ document.getElementById('loginError').textContent = '';
140
+ document.getElementById('loginSuccess').textContent = '';
141
+ document.getElementById('registerError').textContent = '';
142
+ document.getElementById('registerSuccess').textContent = '';
 
 
 
143
  }
144
 
145
+ async function login() {
146
+ const username = document.getElementById('loginUsername').value;
147
+ const password = document.getElementById('loginPassword').value;
 
148
 
149
  try {
150
+ const response = await fetch(`${API_URL}/login`, {
 
 
 
 
 
 
151
  method: 'POST',
152
+ headers: {
153
+ 'Content-Type': 'application/json'
154
+ },
155
+ body: JSON.stringify({ username, password })
156
  });
157
 
158
  const data = await response.json();
159
 
160
  if (response.ok) {
161
+ document.getElementById('loginSuccess').textContent = data.message;
162
+ setTimeout(() => {
163
+ window.location.href = data.redirect_url;
164
+ }, 1000);
 
 
 
165
  } else {
166
+ document.getElementById('loginError').textContent = data.detail;
167
  }
168
  } catch (error) {
169
+ document.getElementById('loginError').textContent = 'حدث خطأ في الاتصال';
 
 
 
 
 
 
170
  }
171
+ }
172
 
173
+ async function register() {
174
+ const username = document.getElementById('registerUsername').value;
175
+ const password = document.getElementById('registerPassword').value;
 
176
 
177
  try {
 
 
178
  const response = await fetch(`${API_URL}/register`, {
179
  method: 'POST',
180
  headers: {
181
+ 'Content-Type': 'application/json'
182
  },
183
+ body: JSON.stringify({ username, password })
 
 
 
 
 
184
  });
185
 
186
  const data = await response.json();
187
 
188
  if (response.ok) {
189
+ document.getElementById('registerSuccess').textContent = data.message;
190
+ setTimeout(() => {
191
+ toggleForms();
192
+ }, 1500);
 
 
193
  } else {
194
+ document.getElementById('registerError').textContent = data.detail;
195
  }
196
  } catch (error) {
197
+ document.getElementById('registerError').textContent = 'حدث خطأ في الاتصال';
 
 
 
 
 
 
198
  }
199
+ }
200
  </script>
201
  </body>
202
  </html>