mirror of
https://github.com/go-gitea/gitea
synced 2024-11-07 18:54:25 +00:00
Avatar autogeneration fixed (#13282)
This mod fixes problem with initial avatar autogeneration and
avatar autogneration after deleting previous avatar.
Related: https://github.com/go-gitea/gitea/issues/13159
Fixes: 80a6b0f5bc
Author-Change-Id: IB#1105243
This commit is contained in:
parent
3d272b899d
commit
28133a801a
@ -191,9 +191,6 @@ func (u *User) BeforeUpdate() {
|
|||||||
if len(u.AvatarEmail) == 0 {
|
if len(u.AvatarEmail) == 0 {
|
||||||
u.AvatarEmail = u.Email
|
u.AvatarEmail = u.Email
|
||||||
}
|
}
|
||||||
if len(u.AvatarEmail) > 0 && u.Avatar == "" {
|
|
||||||
u.Avatar = base.HashEmail(u.AvatarEmail)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u.LowerName = strings.ToLower(u.Name)
|
u.LowerName = strings.ToLower(u.Name)
|
||||||
@ -835,7 +832,6 @@ func CreateUser(u *User) (err error) {
|
|||||||
|
|
||||||
u.LowerName = strings.ToLower(u.Name)
|
u.LowerName = strings.ToLower(u.Name)
|
||||||
u.AvatarEmail = u.Email
|
u.AvatarEmail = u.Email
|
||||||
u.Avatar = base.HashEmail(u.AvatarEmail)
|
|
||||||
if u.Rands, err = GetUserSalt(); err != nil {
|
if u.Rands, err = GetUserSalt(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,9 @@ func (u *User) generateRandomAvatar(e Engine) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("RandomImage: %v", err)
|
return fmt.Errorf("RandomImage: %v", err)
|
||||||
}
|
}
|
||||||
// NOTICE for random avatar, it still uses id as avatar name, but custom avatar use md5
|
|
||||||
// since random image is not a user's photo, there is no security for enumable
|
|
||||||
if u.Avatar == "" {
|
if u.Avatar == "" {
|
||||||
u.Avatar = fmt.Sprintf("%d", u.ID)
|
u.Avatar = base.HashEmail(u.AvatarEmail)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
|
if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
|
||||||
|
@ -121,7 +121,11 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
|
|||||||
func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error {
|
func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error {
|
||||||
ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
|
ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
|
||||||
if len(form.Gravatar) > 0 {
|
if len(form.Gravatar) > 0 {
|
||||||
|
if form.Avatar != nil {
|
||||||
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
|
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
|
||||||
|
} else {
|
||||||
|
ctxUser.Avatar = ""
|
||||||
|
}
|
||||||
ctxUser.AvatarEmail = form.Gravatar
|
ctxUser.AvatarEmail = form.Gravatar
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user