fix random avatars (#1147)

tokarchuk/v1.17
Lunny Xiao 8 years ago committed by GitHub
parent af9998b8a7
commit 5d40db629c
  1. 4
      models/org.go
  2. 8
      models/user.go

@ -135,7 +135,9 @@ func CreateOrganization(org, owner *User) (err error) {
if _, err = sess.Insert(org); err != nil { if _, err = sess.Insert(org); err != nil {
return fmt.Errorf("insert organization: %v", err) 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. // Add initial creator to organization and owner team.
if _, err = sess.Insert(&OrgUser{ if _, err = sess.Insert(&OrgUser{

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

Loading…
Cancel
Save