func updateUser(e Engine, u *User) error { // Organization does not need e-mail. if !u.IsOrganization() { u.Email = strings.ToLower(u.Email) has, err := e.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User)) if err != nil { return err } else if has { return ErrEmailAlreadyUsed{u.Email} } if len(u.AvatarEmail) == 0 { u.AvatarEmail = u.Email } u.Avatar = avatar.HashEmail(u.AvatarEmail) } u.LowerName = strings.ToLower(u.Name) if len(u.Location) > 255 { u.Location = u.Location[:255] } if len(u.Website) > 255 { u.Website = u.Website[:255] } if len(u.Description) > 255 { u.Description = u.Description[:255] } u.FullName = base.Sanitizer.Sanitize(u.FullName) _, err := e.Id(u.Id).AllCols().Update(u) return err }
func TestFetch(t *testing.T) { os.Mkdir(TMPDIR, 0755) defer os.RemoveAll(TMPDIR) hash := avatar.HashEmail("*****@*****.**") a := avatar.New(hash, TMPDIR) a.UpdateTimeout(time.Millisecond * 200) }
// AvatarLink returns avatar link by given e-mail. func AvatarLink(email string) string { if setting.DisableGravatar || setting.OfflineMode { return setting.AppSubUrl + "/img/avatar_default.jpg" } gravatarHash := avatar.HashEmail(email) if setting.Service.EnableCacheAvatar { return setting.AppSubUrl + "/avatar/" + gravatarHash } return setting.GravatarSource + gravatarHash }
// CreateUser creates record of a new user. func CreateUser(u *User) (err error) { if err = IsUsableName(u.Name); err != nil { return err } isExist, err := IsUserExist(0, u.Name) if err != nil { return err } else if isExist { return ErrUserAlreadyExist{u.Name} } isExist, err = IsEmailUsed(u.Email) if err != nil { return err } else if isExist { return ErrEmailAlreadyUsed{u.Email} } u.LowerName = strings.ToLower(u.Name) u.AvatarEmail = u.Email u.Avatar = avatar.HashEmail(u.AvatarEmail) u.Rands = GetUserSalt() u.Salt = GetUserSalt() u.EncodePasswd() sess := x.NewSession() defer sess.Close() if err = sess.Begin(); err != nil { return err } if _, err = sess.Insert(u); err != nil { sess.Rollback() return err } else if err = os.MkdirAll(UserPath(u.Name), os.ModePerm); err != nil { sess.Rollback() return err } return sess.Commit() }
func TestFetchMany(t *testing.T) { os.Mkdir(TMPDIR, 0755) defer os.RemoveAll(TMPDIR) t.Log("start") var n = 5 ch := make(chan bool, n) for i := 0; i < n; i++ { go func(i int) { hash := avatar.HashEmail(strconv.Itoa(i) + "*****@*****.**") a := avatar.New(hash, TMPDIR) a.Update() t.Log("finish", hash) ch <- true }(i) } for i := 0; i < n; i++ { <-ch } t.Log("end") }