mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
9f8890d159
- Declared module Wavelet in backend/go.mod - Replaced github.com/Rain-kl/Wavelet/ with clean Wavelet/ import paths across backend codebase - Updated architecture guards, Makefile, swagger, and build tests - 100% passed all tests, lint checks, and binary compilation
38 lines
966 B
Go
38 lines
966 B
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"Wavelet/core/contracts"
|
|
"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)
|
|
}
|
|
}
|