修正安全码验证后重新查看的提示与注释

This commit is contained in:
xuans committed 2026-09-27 17:50:03 +08:00
1 parent 0cbc67a5e2
commit 645c3444b7
7 files changed
+9 -8

No files matched your search

+1 -1
View File
@@ -300,7 +300,7 @@ func SetSecurityQuestion(ctx *context.Context, w http.ResponseWriter, req *http.
response.NewSuccessResponse(map[string]any{"configured": true}).FPrint(w)
}
// GenerateRecoveryCodes 生成一组只显示一次的离线恢复码。
// GenerateRecoveryCodes 生成一组离线恢复码,未使用的有效恢复码可在安全验证后再次查看。
func GenerateRecoveryCodes(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
if ctx == nil || ctx.UserID <= 0 {
writeSecurityError(w, response.NeedLogin, "请先登录")
+1 -1
View File
@@ -140,7 +140,7 @@ func RevealManagedRecoveryCodes(ctx *context.Context, w http.ResponseWriter, req
response.NewSuccessResponse(map[string]any{"user_id": target.ID, "codes": codes, "revealed": true}).FPrint(w)
}
// GenerateManagedRecoveryCodes 为目标用户生成只显示一次的安全码。
// GenerateManagedRecoveryCodes 为目标用户生成安全码,有管理权限的管理员可在安全验证后再次查看有效安全码。
func GenerateManagedRecoveryCodes(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
var input managedUserSecurityRequest
if err := decodeUserRequest(w, req, &input); err != nil {
+2 -1
View File
@@ -15,7 +15,8 @@ type SecurityQuestion struct {
func (SecurityQuestion) TableName() string { return "security_question" }
// RecoveryCode 保存一次性离线恢复码的 Argon2id 哈希,UsedAt 非空表示已经消费或撤销。
// RecoveryCode 保存一次性离线恢复码的 Argon2id 哈希和用于安全验证后查看的密文。
// UsedAt 非空表示已经消费或撤销,此时密文会被清除,不再允许查看或使用。
type RecoveryCode struct {
ID int `xorm:"id bigint unsigned not null pk autoincr" json:"-"`
UserID int `xorm:"user_id bigint not null index" json:"-"`
+1 -1
View File
@@ -143,7 +143,7 @@ func (s *Service) VerifySecurityQuestion(userID int, answer string) (bool, error
return password.Check(item.AnswerHash, answer)
}
// GenerateRecoveryCodes 撤销旧码并生成一组只返回一次的离线恢复码。
// GenerateRecoveryCodes 撤销旧码并生成一组离线恢复码,保存哈希和受保护的密文以支持安全验证后再次查看。
func (s *Service) GenerateRecoveryCodes(userID int, count int) ([]string, error) {
return s.GenerateRecoveryCodesContext(context.Background(), userID, count)
}