refactor(log): consolidate logging models and update related logic for improved clarity and functionality

This commit is contained in:
Chang lue Tsen
2025-08-20 13:36:06 -04:00
parent 4f32d67113
commit 87c771bbd4
41 changed files with 1082 additions and 707 deletions
+16 -4
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"time"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/model/user"
"github.com/perfect-panel/server/pkg/jwt"
"github.com/perfect-panel/server/pkg/uuidx"
@@ -43,13 +44,24 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res
defer func() {
if userInfo.Id != 0 && loginStatus {
if err := l.svcCtx.UserModel.InsertLoginLog(l.ctx, &user.LoginLog{
UserId: userInfo.Id,
loginLog := log.Login{
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: &loginStatus,
Success: loginStatus,
}
content, _ := loginLog.Marshal()
if err = l.svcCtx.LogModel.Insert(l.ctx, &log.SystemLog{
Id: 0,
Type: log.TypeLogin.Uint8(),
Date: time.Now().Format("2006-01-02"),
ObjectID: userInfo.Id,
Content: string(content),
}); err != nil {
l.Logger.Error("[ResetPassword] insert login log error", logger.Field("error", err.Error()))
l.Errorw("failed to insert login log",
logger.Field("user_id", userInfo.Id),
logger.Field("ip", req.IP),
logger.Field("error", err.Error()),
)
}
}
}()