本文整理汇总了Golang中github.com/varding/wetalk/modules/models.User.Update方法的典型用法代码示例。如果您正苦于以下问题:Golang User.Update方法的具体用法?Golang User.Update怎么用?Golang User.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/varding/wetalk/modules/models.User
的用法示例。
在下文中一共展示了User.Update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UserFollow
func UserFollow(user *models.User, theUser *models.User) {
if theUser.Read() == nil {
var mutual bool
tFollow := models.Follow{User: theUser, FollowUser: user}
if err := tFollow.Read("User", "FollowUser"); err == nil {
mutual = true
}
follow := models.Follow{User: user, FollowUser: theUser, Mutual: mutual}
if err := follow.Insert(); err == nil && mutual {
tFollow.Mutual = mutual
tFollow.Update("Mutual")
}
if nums, err := user.FollowingUsers().Count(); err == nil {
user.Following = int(nums)
user.Update("Following")
}
if nums, err := theUser.FollowerUsers().Count(); err == nil {
theUser.Followers = int(nums)
theUser.Update("Followers")
}
}
}
示例2: Active
// Active implemented check Email actice code.
func (this *RegisterRouter) Active() {
this.TplNames = "auth/active.html"
// no need active
if this.CheckActiveRedirect(false) {
return
}
code := this.GetString(":code")
var user models.User
if auth.VerifyUserActiveCode(&user, code) {
user.IsActive = true
user.Rands = models.GetUserSalt()
if err := user.Update("IsActive", "Rands", "Updated"); err != nil {
beego.Error("Active: user Update ", err)
}
if this.IsLogin {
this.User = user
}
this.Redirect("/active/success", 302)
} else {
this.Data["Success"] = false
}
}
示例3: UserUnFollow
func UserUnFollow(user *models.User, theUser *models.User) {
num, _ := user.FollowingUsers().Filter("FollowUser", theUser.Id).Delete()
if num > 0 {
theUser.FollowingUsers().Filter("FollowUser", user.Id).Update(orm.Params{
"Mutual": false,
})
if nums, err := user.FollowingUsers().Count(); err == nil {
user.Following = int(nums)
user.Update("Following")
}
if nums, err := theUser.FollowerUsers().Count(); err == nil {
theUser.Followers = int(nums)
theUser.Update("Followers")
}
}
}
示例4: SaveUserProfile
func (form *ProfileForm) SaveUserProfile(user *models.User) error {
// set md5 value if the value is an email
if strings.IndexRune(form.GrEmail, '@') != -1 {
form.GrEmail = utils.EncodeMd5(form.GrEmail)
}
changes := utils.FormChanges(user, form)
if len(changes) > 0 {
// if email changed then need re-active
if user.Email != form.Email {
user.IsActive = false
changes = append(changes, "IsActive")
}
utils.SetFormValues(form, user)
return user.Update(changes...)
}
return nil
}
示例5: UploadUserAvatarToQiniu
//upload user avatar
func UploadUserAvatarToQiniu(r io.ReadSeeker, filename string, mime string, bucketName string, user *models.User) error {
var ext string
// test image mime type
switch mime {
case "image/jpeg":
ext = ".jpg"
case "image/png":
ext = ".png"
case "image/gif":
ext = ".gif"
default:
ext = filepath.Ext(filename)
switch ext {
case ".jpg", ".png", ".gif":
default:
return fmt.Errorf("unsupport image format `%s`", filename)
}
}
// decode image
var err error
switch ext {
case ".jpg":
_, err = jpeg.Decode(r)
case ".png":
_, err = png.Decode(r)
case ".gif":
_, err = gif.Decode(r)
}
if err != nil {
return err
}
//reset reader pointer
if _, err := r.Seek(0, 0); err != nil {
return err
}
var data []byte
if data, err = ioutil.ReadAll(r); err != nil {
return err
}
if len(data) > setting.AvatarImageMaxLength {
return fmt.Errorf("avatar image size too large", filename)
}
//reset reader pointer again
if _, err := r.Seek(0, 0); err != nil {
return err
}
//save to qiniu
var uptoken = utils.GetQiniuUptoken(bucketName)
var putRet qio.PutRet
var putExtra = &qio.PutExtra{
MimeType: mime,
}
err = qio.PutWithoutKey(nil, &putRet, uptoken, r, putExtra)
if err != nil {
return err
}
//update user
user.AvatarKey = putRet.Key
if err := user.Update("AvatarKey", "Updated"); err != nil {
return err
}
return nil
}
示例6: SaveAvatarType
//set a new avatar type to user
func SaveAvatarType(user *models.User, avatarType int) error {
user.AvatarType = avatarType
return user.Update("AvatarType", "Updated")
}
示例7: SaveNewPassword
// set a new password to user
func SaveNewPassword(user *models.User, password string) error {
salt := models.GetUserSalt()
user.Password = fmt.Sprintf("%s$%s", salt, utils.EncodePassword(password, salt))
return user.Update("Password", "Rands", "Updated")
}