Use default avatar on error
This commit is contained in:
parent
23f0728879
commit
05e3726415
@ -333,15 +333,14 @@ func (u *User) generateRandomAvatar(e Engine) error {
|
|||||||
// which includes app sub-url as prefix. However, it is possible
|
// which includes app sub-url as prefix. However, it is possible
|
||||||
// to return full URL if user enables Gravatar-like service.
|
// to return full URL if user enables Gravatar-like service.
|
||||||
func (u *User) RelAvatarLink() string {
|
func (u *User) RelAvatarLink() string {
|
||||||
defaultImgURL := setting.AppSubURL + "/img/avatar_default.png"
|
|
||||||
if u.ID == -1 {
|
if u.ID == -1 {
|
||||||
return defaultImgURL
|
return base.DefaultAvatarLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case u.UseCustomAvatar:
|
case u.UseCustomAvatar:
|
||||||
if !com.IsFile(u.CustomAvatarPath()) {
|
if !com.IsFile(u.CustomAvatarPath()) {
|
||||||
return defaultImgURL
|
return base.DefaultAvatarLink()
|
||||||
}
|
}
|
||||||
return setting.AppSubURL + "/avatars/" + u.Avatar
|
return setting.AppSubURL + "/avatars/" + u.Avatar
|
||||||
case setting.DisableGravatar, setting.OfflineMode:
|
case setting.DisableGravatar, setting.OfflineMode:
|
||||||
|
@ -192,6 +192,10 @@ func HashEmail(email string) string {
|
|||||||
return EncodeMD5(strings.ToLower(strings.TrimSpace(email)))
|
return EncodeMD5(strings.ToLower(strings.TrimSpace(email)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DefaultAvatarLink() string {
|
||||||
|
return setting.AppSubURL + "/img/avatar_default.png"
|
||||||
|
}
|
||||||
|
|
||||||
// AvatarLink returns relative avatar link to the site domain by given email,
|
// AvatarLink returns relative avatar link to the site domain by given email,
|
||||||
// which includes app sub-url as prefix. However, it is possible
|
// which includes app sub-url as prefix. However, it is possible
|
||||||
// to return full URL if user enables Gravatar-like service.
|
// to return full URL if user enables Gravatar-like service.
|
||||||
@ -200,6 +204,7 @@ func AvatarLink(email string) string {
|
|||||||
url, err := setting.LibravatarService.FromEmail(email)
|
url, err := setting.LibravatarService.FromEmail(email)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(4, "LibravatarService.FromEmail(email=%s): error %v", email, err)
|
log.Error(4, "LibravatarService.FromEmail(email=%s): error %v", email, err)
|
||||||
|
return DefaultAvatarLink()
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
@ -208,7 +213,7 @@ func AvatarLink(email string) string {
|
|||||||
return setting.GravatarSource + HashEmail(email)
|
return setting.GravatarSource + HashEmail(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
return setting.AppSubURL + "/img/avatar_default.png"
|
return DefaultAvatarLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seconds-based time units
|
// Seconds-based time units
|
||||||
|
Loading…
Reference in New Issue
Block a user