Some checks are pending
Security Checks / security (push) Waiting to run
统一 frontend、backend、test、test-log 和 out 目录,更新构建、部署及测试入口;纳入配置管理兼容与首次安全引导修复;排除本机配置、密钥和测试产物。
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.pcux.cn/xuans/Smail/db"
|
|
"git.pcux.cn/xuans/Smail/dto/response"
|
|
"git.pcux.cn/xuans/Smail/models"
|
|
"git.pcux.cn/xuans/Smail/utils/context"
|
|
)
|
|
|
|
// AcknowledgeSecuritySetup 仅确认当前账号已经查看引导,不代表完成安全设置。
|
|
func AcknowledgeSecuritySetup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
|
if ctx == nil || ctx.UserID <= 0 {
|
|
writeSecurityError(w, response.NeedLogin, "请先登录")
|
|
return
|
|
}
|
|
var user models.User
|
|
found, err := db.Instance.ID(ctx.UserID).Get(&user)
|
|
if err != nil {
|
|
writeSecurityError(w, response.ServerError, "读取安全引导状态失败,请重试")
|
|
return
|
|
}
|
|
if !found || user.Disabled != 0 {
|
|
writeSecurityError(w, response.NeedLogin, "请重新登录")
|
|
return
|
|
}
|
|
if user.SecuritySetupAcknowledged == 0 {
|
|
user.SecuritySetupAcknowledged = 1
|
|
if _, err := db.Instance.ID(ctx.UserID).Cols("security_setup_acknowledged").Update(&user); err != nil {
|
|
writeSecurityError(w, response.ServerError, "保存安全引导状态失败,请重试")
|
|
return
|
|
}
|
|
}
|
|
response.NewSuccessResponse(map[string]any{"showSecuritySetupPrompt": false}).FPrint(w)
|
|
}
|