fix 500 error for ghost avatar (#9537)

This commit is contained in:
6543 2019-12-30 11:55:51 +01:00 committed by Lunny Xiao
parent c0bb5ebc15
commit b4b8c9679f

View file

@ -6,6 +6,7 @@ package user
import ( import (
"strconv" "strconv"
"strings"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
@ -23,7 +24,9 @@ func Avatar(ctx *context.Context) {
log.Debug("Asked avatar for user %v and size %v", userName, size) log.Debug("Asked avatar for user %v and size %v", userName, size)
user, err := models.GetUserByName(userName) var user *models.User
if strings.ToLower(userName) != "ghost" {
user, err = models.GetUserByName(userName)
if err != nil { if err != nil {
if models.IsErrUserNotExist(err) { if models.IsErrUserNotExist(err) {
ctx.ServerError("Requested avatar for invalid user", err) ctx.ServerError("Requested avatar for invalid user", err)
@ -32,6 +35,9 @@ func Avatar(ctx *context.Context) {
} }
return return
} }
} else {
user = models.NewGhostUser()
}
ctx.Redirect(user.RealSizedAvatarLink(size)) ctx.Redirect(user.RealSizedAvatarLink(size))
} }