feat: twofactor bind

This commit is contained in:
henry.chen
2025-07-17 15:24:46 +08:00
parent 91e1731909
commit e5100fa018
11 changed files with 125 additions and 19 deletions

View File

@@ -19,6 +19,7 @@ general: # 常规配置
identifier: <!--more--> # 截取预览标识
length: 400 # 自动截取预览, 字符数
timezone: Asia/Shanghai # 时区
twofactor: true # 是否启用两步验证
disqus: # 评论相关
shortname: xxxxxx
publickey: wdSgxRm9rdGAlLKFcFdToBe3GT4SibmV7Y8EjJQ0r4GWXeKtxpopMAeIeoI2dTEg

View File

@@ -22,10 +22,10 @@
<label for=password class="sr-only">密码</label>
<input type=password id=password name=password class="text-l w-100" placeholder="密码">
</p>
<!-- <p>
{{if .TwoFactor}}<p>
<label for=code class="sr-only">两步验证</label>
<input type=text id=code name=code class="text-l w-100" placeholder="两步验证">
</p> -->
</p>{{end}}
<p class=submit>
<button type=submit class="btn btn-l w-100 primary">登录</button>
</p>

View File

@@ -7,11 +7,37 @@
<div class="row typecho-page-main">
<div class="col-mb-12 col-tb-3">
<p>
<img class="profile-avatar" src="//{{$.Qiniu.Domain}}/static/img/avatar.png" alt="{{.Blogger.BlogName}}" />
<img class="profile-avatar" src="//{{$.Qiniu.Domain}}/static/img/avatar.png" alt="{{.Blogger.BlogName}}" />
</p>
<h2>{{.Blogger.BlogName}}</h2>
<p>{{.Blogger.SubTitle}}</p>
<p>最后登录: {{dateformat .Account.LoginAt "2006/01/02 15:04"}}</p>
{{if .Account.TwoFactorSecret}}
<strong>2FA 已绑定 <a class="unbind-2fa" href="/admin/profile?unbind=true">解绑</a></strong>
{{end}}
{{if $.TwoFactorSecret}}
<strong>2FA 绑定</strong>
<form action="/admin/api/twofactor" method="post" enctype="application/x-www-form-urlencoded">
<ul class="typecho-option">
<li>
<img src="{{$.TwoFactorSecret}}" alt="2fa code" style="width:180px;height:180px;">
</li>
</ul>
<ul class="typecho-option">
<li>
<input id="2fa-0-1" name="code" type="text" class="text" />
<p class="description">
输入 2FA 验证码, 用于确认绑定.</p>
</li>
</ul>
<ul class="typecho-option typecho-option-submit">
<li>
<button type="submit" class="btn primary">
确认绑定</button>
</li>
</ul>
</form>
{{end}}
</div>
<div class="col-mb-12 col-tb-6 col-tb-offset-1 typecho-content-panel" role="form">
<section>