mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-01 06:36:38 +08:00
fb6a3edb89
- Physically purged all legacy internal/ packages, centralized pkg/model/ and pkg/repository/ - Migrated domain models and database repositories into self-contained owner plugins (user, auth, message_gateway, admin, upload, risk_control) - Decoupled cross-plugin interactions via pure core/contracts and typed EventBus - Ensured 100% test coverage pass, zero data races (-race clean), and 0 lint issues in make code-check
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// Copyright 2025 linux.do
|
|
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/Rain-kl/Wavelet/core/contracts"
|
|
"github.com/Rain-kl/Wavelet/pkg/logger"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// LogForAudit 将登录鉴权审计日志写入 Logger
|
|
func LogForAudit(ctx context.Context, user *contracts.UserDTO, c *gin.Context) {
|
|
if user == nil || c == nil {
|
|
return
|
|
}
|
|
auditLog := loginRequiredAuditLog{
|
|
UserID: user.ID,
|
|
Username: user.Username,
|
|
ClientIP: c.ClientIP(),
|
|
Method: c.Request.Method,
|
|
Path: c.Request.URL.Path,
|
|
RequestURI: c.Request.RequestURI,
|
|
UserAgent: c.Request.UserAgent(),
|
|
Referer: c.Request.Referer(),
|
|
}
|
|
auditJSON, err := json.Marshal(auditLog)
|
|
if err != nil {
|
|
logger.ErrorF(ctx, "[LoginRequiredAudit] marshal failed: %v", err)
|
|
logger.DebugF(ctx, "[LoginRequiredAudit] %s %d %s", c.ClientIP(), user.ID, user.Username)
|
|
} else {
|
|
logger.DebugF(ctx, "[LoginRequiredAudit] %s", auditJSON)
|
|
}
|
|
}
|