Browse Source

fix random avatars (#1147)

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

4
models/org.go

@ -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{

8
models/user.go

@ -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)
}

Loading…
Cancel
Save