forked from gitea/gitea
1
0
Fork 0

fix random avatars (#1147)

This commit is contained in:
Lunny Xiao 2017-03-08 23:05:15 +08:00 committed by GitHub
parent af9998b8a7
commit 5d40db629c
2 changed files with 11 additions and 1 deletions

View File

@ -135,7 +135,9 @@ func CreateOrganization(org, owner *User) (err error) {
if _, err = sess.Insert(org); err != nil {
return fmt.Errorf("insert organization: %v", err)
}
org.GenerateRandomAvatar()
if err = org.generateRandomAvatar(sess); err != nil {
return fmt.Errorf("generate random avatar: %v", err)
}
// Add initial creator to organization and owner team.
if _, err = sess.Insert(&OrgUser{

View File

@ -287,6 +287,10 @@ func (u *User) CustomAvatarPath() string {
// GenerateRandomAvatar generates a random avatar for user.
func (u *User) GenerateRandomAvatar() error {
return u.generateRandomAvatar(x)
}
func (u *User) generateRandomAvatar(e Engine) error {
seed := u.Email
if len(seed) == 0 {
seed = u.Name
@ -308,6 +312,10 @@ func (u *User) GenerateRandomAvatar() error {
}
defer fw.Close()
if _, err := e.Id(u.ID).Cols("avatar").Update(u); err != nil {
return err
}
if err = png.Encode(fw, img); err != nil {
return fmt.Errorf("Encode: %v", err)
}