Repository navigation
Expand file tree
/
Copy pathprofile.html
More file actions
277 lines (245 loc) · 13.6 KB
/
Copy pathprofile.html
File metadata and controls
277 lines (245 loc) · 13.6 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
<!DOCTYPE html>
<html class="light" lang="ru">
<head>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>Sellcar - Мой профиль</title>
<link href="/static/style5.css" rel="stylesheet"/>
<link href="/static/style.css" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500;600;700&display=swap" rel="stylesheet"/>
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet"/>
</head>
<body>
<div class="page-container">
<header class="header">
<div class="header-container">
<div class="header-content">
<div class="logo-section">
<a href="index.html" class="logo-link">
<div class="logo">
<span class="material-symbols-outlined logo-icon">directions_car</span>
<h1 class="logo-text">Sellcar</h1>
</div>
</a>
</div>
<div class="user-section">
<div class="user-dropdown">
<button class="user-button">
<img class="user-avatar" data-alt="User avatar" src="/static/default-avatar.png" onerror="this.src='https://via.placeholder.com/40'"/>
<span class="user-name"></span>
<span class="material-symbols-outlined dropdown-icon">expand_more</span>
</button>
<div class="dropdown-menu">
<div class="dropdown-content" aria-labelledby="options-menu" aria-orientation="vertical" role="menu">
<a class="dropdown-item" href="/index.html" role="menuitem">Главная</a>
<a class="dropdown-item" href="/profile.html" role="menuitem">Мой профиль</a>
<a class="dropdown-item" href="/sales.html" role="menuitem">Мои продажи</a>
<a class="dropdown-item" href="/favorites.html" role="menuitem">Избранное</a>
<a class="dropdown-item logout-item" href="#" role="menuitem">Выход</a>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="main-content">
<div class="content-container">
<div class="page-header">
<h1 class="page-title">Мой профиль</h1>
<p class="page-subtitle">Управление вашими личными данными</p>
</div>
<div class="profile-container">
<div class="profile-card">
<div class="avatar-section">
<div class="avatar-container">
<img class="profile-avatar" id="profileAvatar" src="/static/default-avatar.png" onerror="this.src='https://via.placeholder.com/40'" alt="Аватар профиля">
<button class="avatar-edit-button" onclick="document.getElementById('avatarInput').click()">
<span class="material-symbols-outlined">photo_camera</span>
</button>
<input type="file" id="avatarInput" accept="image/*" style="display: none;" onchange="handleAvatarUpload(event)">
</div>
<div class="avatar-info">
<h3 class="avatar-name"></h3>
<p class="avatar-email"></p>
</div>
</div>
<form class="profile-form" id="profileForm">
<div class="form-section">
<h3 class="section-title">Личная информация</h3>
<div class="form-row">
<div class="form-group">
<label class="form-label" for="firstName">Имя</label>
<input type="text" class="form-input" id="firstName" required>
</div>
<div class="form-group">
<label class="form-label" for="lastName">Фамилия</label>
<input type="text" class="form-input" id="lastName" required>
</div>
</div>
<div class="form-group">
<label class="form-label" for="login">Логин</label>
<input type="text" class="form-input" id="login" disabled>
<p class="form-hint">Логин нельзя изменить</p>
</div>
<div class="form-group">
<label class="form-label" for="phone">Номер телефона</label>
<input type="tel" class="form-input" id="phone" value="+7 (999) 123-45-67" required>
</div>
</div>
<div class="form-section">
<h3 class="section-title">Смена пароля</h3>
<div class="form-group">
<label class="form-label" for="currentPassword">Текущий пароль</label>
<input type="password" class="form-input" id="currentPassword" placeholder="Введите текущий пароль">
</div>
<div class="form-group">
<label class="form-label" for="newPassword">Новый пароль</label>
<input type="password" class="form-input" id="newPassword" placeholder="Введите новый пароль">
</div>
<div class="form-group">
<label class="form-label" for="confirmPassword">Подтвердите новый пароль</label>
<input type="password" class="form-input" id="confirmPassword" placeholder="Повторите новый пароль">
</div>
</div>
<div class="form-actions">
<button type="button" class="profile-button profile-button-secondary" onclick="resetForm()">Отмена</button>
<button type="submit" class="profile-button profile-button-primary">Сохранить изменения</button>
</div>
</form>
</div>
</div>
</div>
</main>
<footer class="footer">
<div class="footer-content">
<div class="footer-links">
<a href="#" class="footer-link">Terms</a>
<span class="footer-separator">|</span>
<a href="#" class="footer-link">Privacy</a>
<span class="footer-separator">|</span>
<a href="#" class="footer-link">About</a>
</div>
<div class="footer-copyright">
© 2025 Sellcar. Все права защищены.
</div>
</div>
</footer>
</div>
<script>
async function loadProfile() {
try {
const response = await fetch('/api/user');
if (!response.ok) throw new Error('Ошибка авторизации');
const userInfo = await response.json();
if (userInfo.authenticated) {
const fields = {
'firstName': userInfo.first_name,
'lastName': userInfo.last_name,
'login': userInfo.login,
'phone': userInfo.phone
};
for (const [id, value] of Object.entries(fields)) {
const el = document.getElementById(id);
if (el) el.value = value || '';
}
const avatarName = document.querySelector('.avatar-name');
if (avatarName) {
const fullName = [userInfo.first_name, userInfo.last_name].filter(Boolean).join(' ');
avatarName.textContent = fullName || userInfo.login || 'Пользователь';
}
const avatarEmail = document.querySelector('.avatar-email');
if (avatarEmail) {
avatarEmail.textContent = userInfo.email || '';
}
} else {
window.location.href = '/login';
}
} catch (error) {
console.error('Ошибка загрузки профиля:', error);
}
}
function handlePhoneInput(e) {
let input = e.target;
let matrix = "+7 (___) ___-__-__";
let i = 0;
let def = matrix.replace(/\D/g, "");
let val = input.value.replace(/\D/g, "");
if (def.length >= val.length) val = def;
input.value = matrix.replace(/./g, function(a) {
return /[_\d]/.test(a) && i < val.length ? val.charAt(i++) : i >= val.length ? "" : a;
});
if (e.type === "blur") {
if (input.value.length === 2) input.value = "";
}
}
const phoneInput = document.getElementById('phone');
if (phoneInput) {
phoneInput.addEventListener("input", handlePhoneInput);
phoneInput.addEventListener("focus", handlePhoneInput);
phoneInput.addEventListener("blur", handlePhoneInput);
}
document.addEventListener('DOMContentLoaded', () => {
loadProfile();
const phoneInput = document.getElementById('phone');
if (phoneInput) {
phoneInput.addEventListener('input', handlePhoneInput);
phoneInput.addEventListener('keydown', (e) => {
if (e.target.selectionStart < 3 && (e.key === 'Backspace' || e.key === 'Delete')) {
e.preventDefault();
}
});
}
const form = document.getElementById('profileForm');
if (form) {
form.addEventListener('submit', async function(e) {
e.preventDefault();
const curPass = document.getElementById('currentPassword').value;
const newPass = document.getElementById('newPassword').value;
const confPass = document.getElementById('confirmPassword').value;
if (newPass && newPass !== confPass) {
alert('Новые пароли не совпадают!');
return;
}
const formData = {
first_name: document.getElementById('firstName').value,
last_name: document.getElementById('lastName').value,
phone: document.getElementById('phone').value,
current_password: curPass || null,
new_password: newPass || null
};
try {
const response = await fetch('/api/user/profile', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
});
if (response.ok) {
alert('Профиль успешно обновлен!');
document.getElementById('currentPassword').value = '';
document.getElementById('newPassword').value = '';
document.getElementById('confirmPassword').value = '';
loadProfile();
} else {
const error = await response.json();
alert('Ошибка: ' + (error.detail || 'Неизвестная ошибка'));
}
} catch (error) {
console.error('Ошибка обновления:', error);
alert('Ошибка сети');
}
});
}
});
function resetForm() {
if(confirm('Отменить изменения и перезагрузить данные?')) {
loadProfile();
document.getElementById('currentPassword').value = '';
document.getElementById('newPassword').value = '';
document.getElementById('confirmPassword').value = '';
}
}
</script>
<script src="/static/common.js"></script>
</body>
</html>