This commit is contained in:
1 parent
b77b272a5e
commit
b4337dca40
10 files changed
+314
-11
No files matched your search
@@ -105,7 +105,7 @@ func loginSecurityFields(user *models.User) map[string]any {
|
||||
"recoveryCodesConfigured": false,
|
||||
"showRecoverySetupPrompt": false,
|
||||
"showSecuritySetupPrompt": user != nil && user.SecuritySetupAcknowledged == 0,
|
||||
"webAuthnEnabled": webAuthnRuntime() != nil,
|
||||
"webAuthnEnabled": webAuthnRuntime() != nil,
|
||||
}
|
||||
if user == nil || user.EffectiveRole() == access.RoleSuperAdmin {
|
||||
return fields
|
||||
@@ -270,9 +270,18 @@ func Login(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
for key, value := range loginSecurityFields(user) {
|
||||
result[key] = value
|
||||
}
|
||||
setLoginAuditActor(ctx, user)
|
||||
response.NewSuccessResponse(result).FPrint(w)
|
||||
}
|
||||
|
||||
// setLoginAuditActor 只在完整登录成功后补充审计身份,不将待二次验证视为登录完成。
|
||||
func setLoginAuditActor(ctx *context.Context, user *models.User) {
|
||||
ctx.UserID = user.ID
|
||||
ctx.UserAccount = user.Account
|
||||
ctx.UserName = user.Name
|
||||
ctx.Role = user.EffectiveRole()
|
||||
}
|
||||
|
||||
func Logout(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
csrf.Clear(w, req, !config.DevelopmentMode)
|
||||
if err := session.Instance.Destroy(ctx.Context); err != nil {
|
||||
|
||||
@@ -265,6 +265,7 @@ func completeLoginSession(ctx *context.Context, w http.ResponseWriter, req *http
|
||||
for key, value := range loginSecurityFields(user) {
|
||||
result[key] = value
|
||||
}
|
||||
setLoginAuditActor(ctx, user)
|
||||
response.NewSuccessResponse(result).FPrint(w)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// Run 启动 Smail 主服务。
|
||||
func Run() error {
|
||||
func Run() (err error) {
|
||||
if err := config.InitializeDeployment(config.ROOT_PATH); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func Run() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("启动运行日志失败: %w", err)
|
||||
}
|
||||
defer runtimeLogs.Close()
|
||||
defer finishRuntimeLogs(runtimeLogs, &err)
|
||||
config.MaintainManagedSSLHistory()
|
||||
|
||||
build := buildinfo.Current()
|
||||
@@ -56,6 +56,19 @@ func Run() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// finishRuntimeLogs 在关闭日志文件前记录返回错误或异常,避免致命错误只留在控制台。
|
||||
func finishRuntimeLogs(writer *runtimelog.Writer, runErr *error) {
|
||||
if recovered := recover(); recovered != nil {
|
||||
*runErr = fmt.Errorf("服务启动异常: %v", recovered)
|
||||
}
|
||||
if *runErr != nil {
|
||||
log.WithError(*runErr).Error("服务因致命错误停止")
|
||||
}
|
||||
if err := writer.Close(); err != nil {
|
||||
log.WithError(err).Error("关闭运行日志失败")
|
||||
}
|
||||
}
|
||||
|
||||
// RunAndExit 执行主服务并在发生致命错误时退出。
|
||||
func RunAndExit() {
|
||||
if err := Run(); err != nil {
|
||||
|
||||
@@ -14,7 +14,9 @@ import (
|
||||
// 仅记录明确的变更接口,不将 POST 列表查询误认为操作,也不复制请求或响应载荷。
|
||||
var loggedOperations = map[string]string{
|
||||
"/api/login": "处理账号登录", "/api/logout": "退出登录",
|
||||
"/api/user/create": "创建用户", "/api/user/edit": "编辑用户",
|
||||
"/api/security/login/verify": "完成登录二次验证",
|
||||
"/api/security/webauthn/login/finish": "完成通行密钥登录验证",
|
||||
"/api/user/create": "创建用户", "/api/user/edit": "编辑用户",
|
||||
"/api/group/add": "创建分组", "/api/group/del": "删除分组",
|
||||
"/api/email/del": "删除邮件", "/api/email/move": "移动邮件", "/api/email/read": "修改已读状态",
|
||||
"/api/rule/add": "创建邮件规则", "/api/rule/update": "修改邮件规则", "/api/rule/del": "删除邮件规则",
|
||||
|
||||
Reference in new issue
Block a user