fix 500 error for ghost avatar

This commit is contained in:
6543 2019-12-29 03:34:45 +01:00
parent fd9ad05159
commit 408b522634
No known key found for this signature in database
GPG Key ID: A1CA74D27FD13271
1 changed files with 13 additions and 7 deletions

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,14 +24,19 @@ 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) user := new(models.User)
if err != nil { if strings.ToLower(userName) != "ghost" {
if models.IsErrUserNotExist(err) { user, err = models.GetUserByName(userName)
ctx.ServerError("Requested avatar for invalid user", err) if err != nil {
} else { if models.IsErrUserNotExist(err) {
ctx.ServerError("Retrieving user by name", err) ctx.ServerError("Requested avatar for invalid user", err)
} else {
ctx.ServerError("Retrieving user by name", err)
}
return
} }
return } else {
user = models.NewGhostUser()
} }
ctx.Redirect(user.RealSizedAvatarLink(size)) ctx.Redirect(user.RealSizedAvatarLink(size))