Skip to content

Commit

Permalink
Fix avatar bugs (go-gitea#14217)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored and 6543 committed Jan 2, 2021
1 parent 2fd708a commit 48914fc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions models/user_avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ func (u *User) generateRandomAvatar(e Engine) error {
return fmt.Errorf("RandomImage: %v", err)
}

if u.Avatar == "" {
u.Avatar = base.HashEmail(u.AvatarEmail)
}
u.Avatar = base.HashEmail(seed)

// Don't share the images so that we can delete them easily
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
if err := png.Encode(w, img); err != nil {
log.Error("Encode: %v", err)
Expand Down Expand Up @@ -133,7 +132,7 @@ func (u *User) UploadAvatar(data []byte) error {
// Otherwise, if any of the users delete his avatar
// Other users will lose their avatars too.
u.Avatar = fmt.Sprintf("%x", md5.Sum([]byte(fmt.Sprintf("%d-%x", u.ID, md5.Sum(data)))))
if err = updateUser(sess, u); err != nil {
if err = updateUserCols(sess, u, "use_custom_avatar", "avatar"); err != nil {
return fmt.Errorf("updateUser: %v", err)
}

Expand Down

0 comments on commit 48914fc

Please sign in to comment.