Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avatar autogeneration fixed #13233

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ func (u *User) BeforeUpdate() {
if len(u.AvatarEmail) == 0 {
u.AvatarEmail = u.Email
}
if len(u.AvatarEmail) > 0 && u.Avatar == "" {
u.Avatar = base.HashEmail(u.AvatarEmail)
}
}

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

u.LowerName = strings.ToLower(u.Name)
u.AvatarEmail = u.Email
u.Avatar = base.HashEmail(u.AvatarEmail)
if u.Rands, err = GetUserSalt(); err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions models/user_avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ func (u *User) generateRandomAvatar(e Engine) error {
if err != nil {
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 == "" {
zeripath marked this conversation as resolved.
Show resolved Hide resolved
u.Avatar = fmt.Sprintf("%d", u.ID)
u.Avatar = base.HashEmail(u.AvatarEmail)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
}

if err := storage.SaveFrom(storage.Avatars, u.CustomAvatarRelativePath(), func(w io.Writer) error {
Expand Down
6 changes: 5 additions & 1 deletion routers/user/setting/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
func UpdateAvatarSetting(ctx *context.Context, form auth.AvatarForm, ctxUser *models.User) error {
ctxUser.UseCustomAvatar = form.Source == auth.AvatarLocal
if len(form.Gravatar) > 0 {
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
if form.Avatar != nil {
ctxUser.Avatar = base.EncodeMD5(form.Gravatar)
} else {
ctxUser.Avatar = ""
}
ctxUser.AvatarEmail = form.Gravatar
}

Expand Down