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
+5
View File
@@ -139,6 +139,11 @@ func DiscordOAuth(c *gin.Context) {
})
return
}
if err := user.RestoreIfDeleted("discord", c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("failed to restore user %d: %v", user.Id, err))
common.ApiError(c, err)
return
}
} else {
if common.RegisterEnabled {
if discordUser.ID != "" {
+3 -6
View File
@@ -122,12 +122,9 @@ func GitHubOAuth(c *gin.Context) {
})
return
}
// if user.Id == 0 , user has been deleted
if user.Id == 0 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "用户已注销",
})
if err := user.RestoreIfDeleted("github", c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("failed to restore user %d: %v", user.Id, err))
common.ApiError(c, err)
return
}
} else {
+3 -5
View File
@@ -212,11 +212,9 @@ func LinuxdoOAuth(c *gin.Context) {
})
return
}
if user.Id == 0 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "用户已注销",
})
if err := user.RestoreIfDeleted("linuxdo", c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("failed to restore user %d: %v", user.Id, err))
common.ApiError(c, err)
return
}
} else {
+7 -3
View File
@@ -213,9 +213,9 @@ func findOrCreateOAuthUser(c *gin.Context, provider oauth.Provider, oauthUser *o
if err != nil {
return nil, err
}
// Check if user has been deleted
if user.Id == 0 {
return nil, &OAuthUserDeletedError{}
if err := user.RestoreIfDeleted(provider.GetName(), c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("[OAuth] Failed to restore user %d: %s", user.Id, err.Error()))
return nil, err
}
return user, nil
}
@@ -227,6 +227,10 @@ func findOrCreateOAuthUser(c *gin.Context, provider oauth.Provider, oauthUser *o
if err != nil {
return nil, err
}
if err := user.RestoreIfDeleted(provider.GetName(), c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("[OAuth] Failed to restore user %d: %s", user.Id, err.Error()))
return nil, err
}
if user.Id != 0 {
// Found user with legacy ID, migrate to new ID
common.SysLog(fmt.Sprintf("[OAuth] Migrating user %d from legacy_id=%s to new_id=%s",
+5
View File
@@ -141,6 +141,11 @@ func OidcAuth(c *gin.Context) {
})
return
}
if err := user.RestoreIfDeleted("oidc", c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("failed to restore user %d: %v", user.Id, err))
common.ApiError(c, err)
return
}
} else {
if common.RegisterEnabled {
user.Email = oidcUser.Email
+5
View File
@@ -95,6 +95,11 @@ func TelegramLogin(c *gin.Context) {
})
return
}
if err := user.RestoreIfDeleted("telegram", c.ClientIP()); err != nil {
common.SysError("failed to restore user: " + err.Error())
common.ApiError(c, err)
return
}
setupLogin(&user, c)
}
+1 -1
View File
@@ -51,7 +51,7 @@ func Login(c *gin.Context) {
Username: username,
Password: password,
}
err = user.ValidateAndFill()
err = user.ValidateAndFill(c.ClientIP())
if err != nil {
switch {
case errors.Is(err, model.ErrDatabase):
+3 -5
View File
@@ -82,11 +82,9 @@ func WeChatAuth(c *gin.Context) {
})
return
}
if user.Id == 0 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "用户已注销",
})
if err := user.RestoreIfDeleted("wechat", c.ClientIP()); err != nil {
common.SysError(fmt.Sprintf("failed to restore user %d: %v", user.Id, err))
common.ApiError(c, err)
return
}
} else {