feat: 支持管理员自助修改密码 (#57)

This commit is contained in:
chengma
2026-08-09 16:49:28 +08:00
parent 2cbb98f09c
commit 008bb87620
12 changed files with 446 additions and 19 deletions
+46
View File
@@ -20,6 +20,9 @@
{{end}}
{{if .CurrentUser}}
<span class="nav-user">{{.CurrentUser.Username}}</span>
{{if .CurrentUser.IsAdmin}}
<button type="button" class="nav-account" data-modal-open="change-password-modal">修改密码</button>
{{end}}
<form class="nav-logout" method="post" action="/logout">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
<button type="submit">退出登录</button>
@@ -27,5 +30,48 @@
{{end}}
</nav>
{{if and .CurrentUser .CurrentUser.IsAdmin}}
<div class="modal-backdrop" id="change-password-modal" {{if not .PasswordChangeOpen}}hidden{{end}}>
<div class="modal modal-narrow" role="dialog" aria-modal="true" aria-labelledby="change-password-title">
<div class="modal-head">
<h2 id="change-password-title">修改我的密码</h2>
<button type="button" class="modal-x" data-modal-close aria-label="关闭">×</button>
</div>
<form method="post" action="/account/change-password">
<div class="modal-body form-stack">
<p class="hint">修改成功后,这个管理员在所有浏览器中的登录都会失效,需要使用新密码重新登录。</p>
<div class="field">
<label for="current-password">当前密码</label>
<input id="current-password" type="password" name="current_password" required
autocomplete="current-password" {{if or (not .PasswordChangeField) (eq .PasswordChangeField "current_password")}}autofocus{{end}}
{{if eq .PasswordChangeField "current_password"}}aria-invalid="true" aria-describedby="current-password-error"{{end}}>
{{if eq .PasswordChangeField "current_password"}}<small id="current-password-error" class="field-error" role="alert">{{.PasswordChangeError}}</small>{{end}}
</div>
<div class="field">
<label for="changed-password">新密码</label>
<input id="changed-password" type="password" name="new_password" minlength="6"
maxlength="72" required autocomplete="new-password" {{if eq .PasswordChangeField "new_password"}}autofocus aria-invalid="true" aria-describedby="changed-password-error"{{end}}>
{{if eq .PasswordChangeField "new_password"}}
<small id="changed-password-error" class="field-error" role="alert">{{.PasswordChangeError}}</small>
{{else}}<small>至少 6 个字符,最多 72 个字节。</small>{{end}}
</div>
<div class="field">
<label for="changed-password-confirm">确认新密码</label>
<input id="changed-password-confirm" type="password" name="password_confirm"
minlength="6" maxlength="72" required autocomplete="new-password" {{if eq .PasswordChangeField "password_confirm"}}autofocus aria-invalid="true" aria-describedby="changed-password-confirm-error"{{end}}>
{{if eq .PasswordChangeField "password_confirm"}}<small id="changed-password-confirm-error" class="field-error" role="alert">{{.PasswordChangeError}}</small>{{end}}
</div>
<input type="hidden" name="next" value="{{.PasswordReturnPath}}">
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
</div>
<div class="modal-foot">
<button type="button" data-modal-close>取消</button>
<button type="submit" class="primary">修改密码</button>
</div>
</form>
</div>
</div>
{{end}}
<main class="page">
{{end}}