fix: restore soft-deleted users on login

This commit is contained in:
2026-06-15 07:36:13 +08:00
parent 04d30f9dd1
commit 346cf0e4a6
13 changed files with 234 additions and 37 deletions
+27
View File
@@ -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