本文整理匯總了Golang中github.com/beego/wetalk/modules/models.User.Update方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.Update方法的具體用法?Golang User.Update怎麽用?Golang User.Update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/beego/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: 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")
}
示例6: 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
}
示例7: SaveAvatarType
//set a new avatar type to user
func SaveAvatarType(user *models.User, avatarType int) error {
user.AvatarType = avatarType
return user.Update("AvatarType", "Updated")
}