mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
fix random avatars (#1147)
This commit is contained in:
parent
af9998b8a7
commit
5d40db629c
2 changed files with 11 additions and 1 deletions
|
@ -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{
|
||||
|
|
|
@ -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…
Reference in a new issue