Skip to content

Commit 543dd98

Browse files
pboguslawskiaswild
authored andcommitted
Avatar autogeneration fixed
This mod fixes problem with initial avatar autogeneration and avatar autogneration after deleting previous avatar. Related: go-gitea#13159 Fixes: 80a6b0f Author-Change-Id: IB#1105243
1 parent d6b3e36 commit 543dd98

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

models/user.go

-4
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ func (u *User) BeforeUpdate() {
191191
if len(u.AvatarEmail) == 0 {
192192
u.AvatarEmail = u.Email
193193
}
194-
if len(u.AvatarEmail) > 0 && u.Avatar == "" {
195-
u.Avatar = base.HashEmail(u.AvatarEmail)
196-
}
197194
}
198195

199196
u.LowerName = strings.ToLower(u.Name)
@@ -835,7 +832,6 @@ func CreateUser(u *User) (err error) {
835832

836833
u.LowerName = strings.ToLower(u.Name)
837834
u.AvatarEmail = u.Email
838-
u.Avatar = base.HashEmail(u.AvatarEmail)
839835
if u.Rands, err = GetUserSalt(); err != nil {
840836
return err
841837
}

models/user_avatar.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ func (u *User) generateRandomAvatar(e Engine) error {
3939
if err != nil {
4040
return fmt.Errorf("RandomImage: %v", err)
4141
}
42-
// NOTICE for random avatar, it still uses id as avatar name, but custom avatar use md5
43-
// since random image is not a user's photo, there is no security for enumable
42+
4443
if u.Avatar == "" {
45-
u.Avatar = fmt.Sprintf("%d", u.ID)
44+
u.Avatar = base.HashEmail(u.AvatarEmail)
4645
}
4746

4847
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {

routers/user/setting/profile.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
121121
func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error {
122122
ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
123123
if len(form.Gravatar) > 0 {
124-
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
124+
if form.Avatar != nil {
125+
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
126+
} else {
127+
ctxUser.Avatar = ""
128+
}
125129
ctxUser.AvatarEmail = form.Gravatar
126130
}
127131

0 commit comments

Comments
 (0)