fix: restore soft-deleted users on login
This commit is contained in:
@@ -88,6 +88,33 @@ func GetLogByTokenId(tokenId int) (logs []*Log, err error) {
|
||||
return logs, err
|
||||
}
|
||||
|
||||
// RecordUserRestoreLog writes an audit-log entry whenever a soft-deleted user
|
||||
// is automatically restored (e.g. by logging in again via password or OAuth).
|
||||
// `source` describes the trigger, e.g. "github", "linuxdo", "telegram", "password".
|
||||
// `callerIp` may be empty when the call originates from the model layer.
|
||||
func RecordUserRestoreLog(userId int, source string, callerIp string) {
|
||||
username, _ := GetUsernameById(userId, false)
|
||||
other := map[string]interface{}{}
|
||||
if source != "" {
|
||||
other["restore_source"] = source
|
||||
}
|
||||
if callerIp != "" {
|
||||
other["caller_ip"] = callerIp
|
||||
}
|
||||
log := &Log{
|
||||
UserId: userId,
|
||||
Username: username,
|
||||
CreatedAt: common.GetTimestamp(),
|
||||
Type: LogTypeSystem,
|
||||
Content: fmt.Sprintf("软删除用户被自动恢复,来源 %s", source),
|
||||
Ip: callerIp,
|
||||
Other: common.MapToJsonStr(other),
|
||||
}
|
||||
if err := LOG_DB.Create(log).Error; err != nil {
|
||||
common.SysLog("failed to record user restore log: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func RecordLog(userId int, logType int, content string) {
|
||||
if logType == LogTypeConsume && !common.LogConsumeEnabled {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user