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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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ثبت نام در پلتفرم آموزشی - RewardApp</title>
    <meta name="description" content="ثبت نام در پلتفرم آموزش توسعه وب">
    
    <!-- استایل‌ها -->
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/auth.css">
    <link rel="stylesheet" href="css/responsive.css">
    
    <style>
        .auth-container {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
        }
        
        .auth-card {
            background: white;
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 20px 60px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 450px;
        }
        
        .auth-logo {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .auth-logo h1 {
            color: #4a5568;
            margin-bottom: 10px;
            font-size: 24px;
        }
        
        .auth-logo p {
            color: #718096;
            font-size: 14px;
        }
        
        .auth-form .form-group {
            margin-bottom: 20px;
        }
        
        .auth-form label {
            display: block;
            margin-bottom: 8px;
            color: #4a5568;
            font-weight: 600;
        }
        
        .auth-form input, .auth-form select {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e2e8f0;
            border-radius: 10px;
            font-size: 16px;
            transition: all 0.3s ease;
        }
        
        .auth-form input:focus, .auth-form select:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .btn-auth {
            width: 100%;
            padding: 12px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        
        .btn-auth:hover {
            background: #5a67d8;
            transform: translateY(-2px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
        }
        
        .auth-links {
            text-align: center;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #e2e8f0;
        }
        
        .auth-links a {
            color: #667eea;
            text-decoration: none;
            margin: 0 10px;
            transition: color 0.3s ease;
        }
        
        .auth-links a:hover {
            color: #5a67d8;
            text-decoration: underline;
        }
        
        .error-message {
            background: #fed7d7;
            color: #742a2a;
            padding: 10px;
            border-radius: 8px;
            margin-bottom: 20px;
            text-align: center;
            display: none;
        }
        
        .success-message {
            background: #c6f6d5;
            color: #22543d;
            padding: 10px;
            border-radius: 8px;
            margin-bottom: 20px;
            text-align: center;
            display: none;
        }
        
        .password-strength {
            margin-top: 5px;
            font-size: 12px;
        }
        
        .strength-weak { color: #e53e3e; }
        .strength-medium { color: #dd6b20; }
        .strength-strong { color: #38a169; }
        
        @media (max-width: 480px) {
            .form-row {
                grid-template-columns: 1fr;
            }
            
            .auth-card {
                padding: 30px 20px;
            }
        }
    </style>
</head>
<body>
    <div class="auth-container">
        <div class="auth-card">
            <div class="auth-logo">
                <h1>🎓 RewardApp</h1>
                <p>ثبت نام در پلتفرم آموزشی</p>
            </div>
            
            <div id="errorMessage" class="error-message"></div>
            <div id="successMessage" class="success-message"></div>
            
            <form id="registerForm" class="auth-form">
                <div class="form-row">
                    <div class="form-group">
                        <label for="firstName">نام</label>
                        <input 
                            type="text" 
                            id="firstName" 
                            name="firstName" 
                            placeholder="نام خود را وارد کنید"
                        >
                    </div>
                    
                    <div class="form-group">
                        <label for="lastName">نام خانوادگی</label>
                        <input 
                            type="text" 
                            id="lastName" 
                            name="lastName" 
                            placeholder="نام خانوادگی خود را وارد کنید"
                        >
                    </div>
                </div>
                
                <div class="form-group">
                    <label for="username">نام کاربری *</label>
                    <input 
                        type="text" 
                        id="username" 
                        name="username" 
                        placeholder="نام کاربری مورد نظر"
                        required
                    >
                    <small style="color: #718096; font-size: 12px;">نام کاربری باید 3-20 کاراکتر و فقط شامل حروف، اعداد و زیرخط باشد</small>
                </div>
                
                <div class="form-group">
                    <label for="email">ایمیل *</label>
                    <input 
                        type="email" 
                        id="email" 
                        name="email" 
                        placeholder="example@email.com"
                        required
                    >
                </div>
                
                <div class="form-group">
                    <label for="password">رمز عبور *</label>
                    <input 
                        type="password" 
                        id="password" 
                        name="password" 
                        placeholder="حداقل 6 کاراکتر"
                        required
                        oninput="checkPasswordStrength(this.value)"
                    >
                    <div id="passwordStrength" class="password-strength"></div>
                </div>
                
                <div class="form-group">
                    <label for="confirmPassword">تکرار رمز عبور *</label>
                    <input 
                        type="password" 
                        id="confirmPassword" 
                        name="confirmPassword" 
                        placeholder="تکرار رمز عبور"
                        required
                    >
                </div>
                
                <div class="form-group">
                    <label for="role">نقش کاربری</label>
                    <select id="role" name="role">
                        <option value="student">دانشجو</option>
                        <option value="instructor">مربی</option>
                    </select>
                </div>
                
                <div class="form-group">
                    <label for="bio">درباره من</label>
                    <textarea 
                        id="bio" 
                        name="bio" 
                        rows="3" 
                        placeholder="توضیح مختصری درباره خودتان..."
                        style="width: 100%; padding: 12px 16px; border: 2px solid #e2e8f0; border-radius: 10px; font-size: 16px; resize: vertical; font-family: inherit;"
                    ></textarea>
                </div>
                
                <div class="form-group" style="display: flex; align-items: start; gap: 10px; font-size: 14px;">
                    <input type="checkbox" id="terms" name="terms" required style="width: auto; margin-top: 3px;">
                    <label for="terms" style="margin: 0;">
                        با <a href="#" style="color: #667eea;">قوانین و مقررات</a> پلتفرم موافقم
                    </label>
                </div>
                
                <button type="submit" class="btn-auth">ایجاد حساب کاربری</button>
            </form>
            
            <div class="auth-links">
                <a href="login.html">قبلاً ثبت نام کرده‌اید؟ ورود</a>
                <br>
                <a href="index.html">بازگشت به صفحه اصلی</a>
            </div>
        </div>
    </div>

    <!-- اسکریپت‌های مورد نیاز -->
    <script src="js/auth/authentication.js"></script>
    <script src="js/auth/user_management.js"></script>
    <script src="js/middleware/validation_middleware.js"></script>
    
    <script>
        class RegisterPage {
            constructor() {
                this.init();
            }
            
            init() {
                this.setupEventListeners();
                this.checkExistingAuth();
            }
            
            setupEventListeners() {
                const registerForm = document.getElementById('registerForm');
                if (registerForm) {
                    registerForm.addEventListener('submit', (e) => {
                        e.preventDefault();
                        this.handleRegistration();
                    });
                }
                
                // مدیریت نمایش/پنهان کردن پیام‌ها
                document.addEventListener('click', () => {
                    this.hideMessages();
                });
            }
            
            checkExistingAuth() {
                if (authManager.isAuthenticated()) {
                    this.showMessage('شما قبلاً وارد شده‌اید. در حال انتقال...', 'success');
                    setTimeout(() => {
                        window.location.href = 'index.html';
                    }, 2000);
                }
            }
            
            async handleRegistration() {
                const formData = new FormData(document.getElementById('registerForm'));
                const data = {
                    firstName: formData.get('firstName')?.trim(),
                    lastName: formData.get('lastName')?.trim(),
                    username: formData.get('username').trim(),
                    email: formData.get('email').trim(),
                    password: formData.get('password'),
                    confirmPassword: formData.get('confirmPassword'),
                    role: formData.get('role'),
                    bio: formData.get('bio')?.trim(),
                    terms: formData.get('terms')
                };
                
                // اعتبارسنجی
                const validation = ValidationMiddleware.validateRegisterData(data);
                if (!validation.isValid) {
                    this.showMessage(validation.errors.join(' • '), 'error');
                    return;
                }
                
                // بررسی قوانین
                if (!data.terms) {
                    this.showMessage('پذیرش قوانین و مقررات الزامی است', 'error');
                    return;
                }
                
                // ایجاد پروفایل
                const profile = {
                    fullName: `${data.firstName || ''} ${data.lastName || ''}`.trim(),
                    bio: data.bio || ''
                };
                
                // ثبت نام کاربر
                const result = authManager.registerUser(
                    data.username,
                    data.email,
                    data.password,
                    data.role,
                    profile
                );
                
                if (result.success) {
                    this.showMessage('حساب کاربری با موفقیت ایجاد شد! در حال انتقال به صفحه ورود...', 'success');
                    
                    // پاک کردن فرم
                    document.getElementById('registerForm').reset();
                    document.getElementById('passwordStrength').textContent = '';
                    
                    setTimeout(() => {
                        window.location.href = 'login.html';
                    }, 3000);
                } else {
                    this.showMessage(result.message || 'خطا در ایجاد حساب کاربری', 'error');
                }
            }
            
            showMessage(message, type = 'error') {
                const errorElement = document.getElementById('errorMessage');
                const successElement = document.getElementById('successMessage');
                
                if (type === 'error') {
                    errorElement.textContent = message;
                    errorElement.style.display = 'block';
                    successElement.style.display = 'none';
                } else {
                    successElement.textContent = message;
                    successElement.style.display = 'block';
                    errorElement.style.display = 'none';
                }
                
                // پنهان کردن خودکار پیام بعد از 5 ثانیه
                setTimeout(() => {
                    this.hideMessages();
                }, 5000);
            }
            
            hideMessages() {
                document.getElementById('errorMessage').style.display = 'none';
                document.getElementById('successMessage').style.display = 'none';
            }
        }
        
        // تابع بررسی قدرت رمز عبور
        function checkPasswordStrength(password) {
            const strengthElement = document.getElementById('passwordStrength');
            if (!password) {
                strengthElement.textContent = '';
                return;
            }
            
            let strength = 0;
            let feedback = '';
            
            if (password.length >= 6) strength++;
            if (password.length >= 8) strength++;
            if (/[A-Z]/.test(password)) strength++;
            if (/[0-9]/.test(password)) strength++;
            if (/[^A-Za-z0-9]/.test(password)) strength++;
            
            if (strength <= 2) {
                feedback = 'ضعیف';
                strengthElement.className = 'password-strength strength-weak';
            } else if (strength <= 4) {
                feedback = 'متوسط';
                strengthElement.className = 'password-strength strength-medium';
            } else {
                feedback = 'قوی';
                strengthElement.className = 'password-strength strength-strong';
            }
            
            strengthElement.textContent = `قدرت رمز: ${feedback}`;
        }
        
        // راه‌اندازی صفحه ثبت نام هنگام بارگذاری
        document.addEventListener('DOMContentLoaded', () => {
            new RegisterPage();
        });
        
        // نمایش خطاهای عمومی
        window.addEventListener('error', (event) => {
            console.error('Global error:', event.error);
        });
    </script>
</body>
</html>