diff --git a/accounts/templates/accounts/profile.html b/accounts/templates/accounts/profile.html
index 4afde20..2431e5b 100644
--- a/accounts/templates/accounts/profile.html
+++ b/accounts/templates/accounts/profile.html
@@ -29,6 +29,13 @@
.image-item .info { padding: 10px; font-size: 12px; color: #888; text-align: center; }
.no-data { text-align: center; color: #999; padding: 40px; }
+ .form-group { margin-bottom: 14px; }
+ .form-group label { display:block; margin-bottom: 6px; font-weight: 600; color: #333; }
+ .form-group input { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; box-sizing: border-box; }
+ .btn { padding: 10px 14px; border: none; border-radius: 10px; cursor: pointer; background: #4f46e5; color: #fff; }
+ .msg { margin-top: 10px; font-size: 13px; }
+ .msg.error { color: #b91c1c; }
+ .msg.success { color: #166534; }
/* 图片放大模态框 */
.image-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 2000; }
@@ -65,6 +72,28 @@
+ {% if permission_name != "管理员" and not profile_user.manage_key %}
+
+ {% endif %}
+
我的提交
{% if achievements %}
@@ -128,6 +157,54 @@
const modal = document.getElementById('imageModal');
if (event.target == modal) closeModal();
}
+
+ const pwdForm = document.getElementById('pwdForm');
+ if (pwdForm) {
+ pwdForm.addEventListener('submit', async (e) => {
+ e.preventDefault();
+ const msg = document.getElementById('pwdMsg');
+ msg.textContent = '';
+ msg.className = 'msg';
+
+ const pwd = (document.getElementById('newPassword').value || '').trim();
+ const cpwd = (document.getElementById('confirmPassword').value || '').trim();
+ if (pwd !== cpwd) {
+ msg.textContent = '密码和确认密码不匹配';
+ msg.className = 'msg error';
+ return;
+ }
+ if (pwd.length < 6) {
+ msg.textContent = '密码长度至少为6位';
+ msg.className = 'msg error';
+ return;
+ }
+ try {
+ const csrftoken = getCookie('csrftoken');
+ const resp = await fetch(`/elastic/users/{{ profile_user.user_id }}/update/`, {
+ method: 'POST',
+ credentials: 'same-origin',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'X-CSRFToken': csrftoken || ''
+ },
+ body: JSON.stringify({ password: pwd })
+ });
+ const data = await resp.json();
+ if (resp.ok && data.status === 'success') {
+ msg.textContent = '修改成功';
+ msg.className = 'msg success';
+ document.getElementById('newPassword').value = '';
+ document.getElementById('confirmPassword').value = '';
+ } else {
+ msg.textContent = data.message || '操作失败';
+ msg.className = 'msg error';
+ }
+ } catch (err) {
+ msg.textContent = '操作失败';
+ msg.className = 'msg error';
+ }
+ });
+ }