本文整理汇总了Golang中github.com/beego/wetalk/modules/models.User.Read方法的典型用法代码示例。如果您正苦于以下问题:Golang User.Read方法的具体用法?Golang User.Read怎么用?Golang User.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/beego/wetalk/modules/models.User
的用法示例。
在下文中一共展示了User.Read方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LoginUser
func (p *socialAuther) LoginUser(ctx *context.Context, uid int) (string, error) {
user := models.User{Id: uid}
if user.Read() == nil {
auth.LoginUser(&user, ctx, true)
}
return auth.GetLoginRedirect(ctx), nil
}
示例2: LoginUserFromRememberCookie
func LoginUserFromRememberCookie(user *models.User, ctx *context.Context) (success bool) {
userName := ctx.GetCookie(setting.CookieUserName)
if len(userName) == 0 {
return false
}
defer func() {
if !success {
DeleteRememberCookie(ctx)
}
}()
user.UserName = userName
if err := user.Read("UserName"); err != nil {
return false
}
secret := utils.EncodeMd5(user.Rands + user.Password)
value, _ := ctx.GetSecureCookie(secret, setting.CookieRememberName)
if value != userName {
return false
}
LoginUser(user, ctx, true)
return true
}
示例3: 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")
}
}
}
示例4: Valid
func (form *CommentAdminForm) Valid(v *validation.Validation) {
user := models.User{Id: form.User}
if user.Read() != nil {
v.SetError("User", "admin.not_found_by_id")
}
post := models.Post{Id: form.Post}
if post.Read() != nil {
v.SetError("Post", "admin.not_found_by_id")
}
}
示例5: GetUserFromSession
// get user if key exist in session
func GetUserFromSession(user *models.User, sess session.Store) bool {
id := GetUserIdFromSession(sess)
if id > 0 {
u := models.User{Id: id}
if u.Read() == nil {
*user = u
return true
}
}
return false
}
示例6: getVerifyUser
// get user by erify code
func getVerifyUser(user *models.User, code string) bool {
if len(code) <= utils.TimeLimitCodeLength {
return false
}
// use tail hex username query user
hexStr := code[utils.TimeLimitCodeLength:]
if b, err := hex.DecodeString(hexStr); err == nil {
user.UserName = string(b)
if user.Read("UserName") == nil {
return true
}
}
return false
}
示例7: getUser
func (this *UserRouter) getUser(user *models.User) bool {
username := this.GetString(":username")
user.UserName = username
err := user.Read("UserName")
if err != nil {
this.Abort("404")
return true
}
IsFollowed := false
if this.IsLogin {
if this.User.Id != user.Id {
IsFollowed = this.User.FollowingUsers().Filter("FollowUser", user.Id).Exist()
}
}
this.Data["TheUser"] = &user
this.Data["IsFollowed"] = IsFollowed
return false
}
示例8: Valid
func (form *PageAdminForm) Valid(v *validation.Validation) {
user := models.User{Id: form.User}
if user.Read() != nil {
v.SetError("User", "admin.not_found_by_id")
}
}