summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2017-06-29 21:30:05 -0300
committerGitHub <noreply@github.com>2017-06-29 21:30:05 -0300
commit935b40fd8e5bbdc2a1ce1c64b72e1d3fcd9ba147 (patch)
tree33f57065b8a7e756683c6367ab292ba94c64fc2b
parent783b1967e257fdba2bd593d9f2108da2010b7448 (diff)
parent2b410e44b2813648d670feb2fd543638bd8a4c80 (diff)
downloadgitea-935b40fd8e5bbdc2a1ce1c64b72e1d3fcd9ba147.tar.gz
gitea-935b40fd8e5bbdc2a1ce1c64b72e1d3fcd9ba147.zip
Merge pull request #2083 from ethantkoenig/check_err/org_avatar
Don't ignore gravatar error
-rw-r--r--models/user.go5
-rw-r--r--modules/base/tool.go14
2 files changed, 13 insertions, 6 deletions
diff --git a/models/user.go b/models/user.go
index 6484c8cf69..2a4fb557db 100644
--- a/models/user.go
+++ b/models/user.go
@@ -333,15 +333,14 @@ func (u *User) generateRandomAvatar(e Engine) error {
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func (u *User) RelAvatarLink() string {
- defaultImgURL := setting.AppSubURL + "/img/avatar_default.png"
if u.ID == -1 {
- return defaultImgURL
+ return base.DefaultAvatarLink()
}
switch {
case u.UseCustomAvatar:
if !com.IsFile(u.CustomAvatarPath()) {
- return defaultImgURL
+ return base.DefaultAvatarLink()
}
return setting.AppSubURL + "/avatars/" + u.Avatar
case setting.DisableGravatar, setting.OfflineMode:
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 8952e7a8c9..543775e0df 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -192,13 +192,21 @@ func HashEmail(email string) string {
return EncodeMD5(strings.ToLower(strings.TrimSpace(email)))
}
+// DefaultAvatarLink the default avatar link
+func DefaultAvatarLink() string {
+ return setting.AppSubURL + "/img/avatar_default.png"
+}
+
// AvatarLink returns relative avatar link to the site domain by given email,
// which includes app sub-url as prefix. However, it is possible
// to return full URL if user enables Gravatar-like service.
func AvatarLink(email string) string {
if setting.EnableFederatedAvatar && setting.LibravatarService != nil {
- // TODO: This doesn't check any error. AvatarLink should return (string, error)
- url, _ := setting.LibravatarService.FromEmail(email)
+ url, err := setting.LibravatarService.FromEmail(email)
+ if err != nil {
+ log.Error(4, "LibravatarService.FromEmail(email=%s): error %v", email, err)
+ return DefaultAvatarLink()
+ }
return url
}
@@ -206,7 +214,7 @@ func AvatarLink(email string) string {
return setting.GravatarSource + HashEmail(email)
}
- return setting.AppSubURL + "/img/avatar_default.png"
+ return DefaultAvatarLink()
}
// Seconds-based time units