Skip to content

Commit e2252a6

Browse files
committed
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 9658610 commit e2252a6

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
@@ -190,9 +190,6 @@ func (u *User) BeforeUpdate() {
190190
if len(u.AvatarEmail) == 0 {
191191
u.AvatarEmail = u.Email
192192
}
193-
if len(u.AvatarEmail) > 0 && u.Avatar == "" {
194-
u.Avatar = base.HashEmail(u.AvatarEmail)
195-
}
196193
}
197194

198195
u.LowerName = strings.ToLower(u.Name)
@@ -822,7 +819,6 @@ func CreateUser(u *User) (err error) {
822819

823820
u.LowerName = strings.ToLower(u.Name)
824821
u.AvatarEmail = u.Email
825-
u.Avatar = base.HashEmail(u.AvatarEmail)
826822
if u.Rands, err = GetUserSalt(); err != nil {
827823
return err
828824
}

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)