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

Fix random avatar begin regenerated on every page refresh #1131

Closed
wants to merge 1 commit into from
Closed

Fix random avatar begin regenerated on every page refresh #1131

wants to merge 1 commit into from

Conversation

andreynering
Copy link
Contributor

See this line:

if !com.IsFile(u.CustomAvatarPath()) {

This line was always returning true because u.CustomAvatarPath() uses a email hash to generate the avatar path, but it was actually generated and served by the user ID.

Using hash on all cases is more consistent and fixes the issue.

See this line: https://github.com/go-gitea/gitea/blob/848293671b5d9c31ce3eb9ad8a1f130edd0ee7c5/models/user.go#L335

This line was always returning true because u.CustomAvatarPath()
uses a email hash to generate the avatar path, but it was actually
generated and served by the user ID.

Using hash on all cases is more consistent and fixes the issue.
@andreynering andreynering added this to the 1.1.0 milestone Mar 7, 2017
@andreynering andreynering changed the title Fix ramdom avatar begin regenerated on every page refresh Fix random avatar begin regenerated on every page refresh Mar 7, 2017
@@ -296,9 +296,6 @@ func (u *User) GenerateRandomAvatar() 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
u.Avatar = fmt.Sprintf("%d", u.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will fix when u.Avatar is empty, then line 305 fw, err := os.Create(u.CustomAvatarPath()) will create an avatars file. This bug is reported by #1114.

@@ -296,9 +296,6 @@ func (u *User) GenerateRandomAvatar() 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if u.Avatar == "" {
 u.Avatar = fmt.Sprintf("%d", u.ID)
}

maybe add this line is OK.

@lunny lunny mentioned this pull request Mar 8, 2017
@lunny lunny closed this in #1147 Mar 8, 2017
@andreynering andreynering deleted the fix-ramdom-avatar-always-being-regenerating branch March 13, 2017 12:19
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants