本文整理汇总了Golang中github.com/varding/wetalk/modules/models.User类的典型用法代码示例。如果您正苦于以下问题:Golang User类的具体用法?Golang User怎么用?Golang User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RegisterUser
// register create user
func RegisterUser(user *models.User, username, email, password string, locale i18n.Locale) error {
// use random salt encode password
salt := models.GetUserSalt()
pwd := utils.EncodePassword(password, salt)
user.UserName = strings.ToLower(username)
user.Email = strings.ToLower(email)
// save salt and encode password, use $ as split char
user.Password = fmt.Sprintf("%s$%s", salt, pwd)
// save md5 email value for gravatar
user.GrEmail = utils.EncodeMd5(user.Email)
// Use username as default nickname.
user.NickName = user.UserName
//set default language
if locale.Lang == "en-US" {
user.Lang = setting.LangEnUS
} else {
user.Lang = setting.LangZhCN
}
//set default avatar
user.AvatarType = setting.AvatarTypeGravatar
return user.Insert()
}
开发者ID:varding,项目名称:wetalk,代码行数:29,代码来源:auth.go
示例2: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:7,代码来源:auth_social.go
示例3: 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
}
}
开发者ID:varding,项目名称:wetalk,代码行数:29,代码来源:auth.go
示例4: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:27,代码来源:auth.go
示例5: ResetPost
// Reset implemented user password reset.
func (this *ForgotRouter) ResetPost() {
this.TplNames = "auth/reset.html"
code := this.GetString(":code")
this.Data["Code"] = code
var user models.User
if auth.VerifyUserResetPwdCode(&user, code) {
this.Data["Success"] = true
form := auth.ResetPwdForm{}
if this.ValidFormSets(&form) == false {
return
}
user.IsActive = true
user.Rands = models.GetUserSalt()
if err := auth.SaveNewPassword(&user, form.Password); err != nil {
beego.Error("ResetPost Save New Password: ", err)
}
if this.IsLogin {
auth.LogoutUser(this.Ctx)
}
this.FlashRedirect("/login", 302, "ResetSuccess")
} else {
this.Data["Success"] = false
}
}
开发者ID:varding,项目名称:wetalk,代码行数:34,代码来源:auth.go
示例6: Valid
func (form *PostAdminForm) Valid(v *validation.Validation) {
user := models.User{Id: form.User}
if user.Read() != nil {
v.SetError("User", "admin.not_found_by_id")
}
user.Id = form.LastReply
if user.Read() != nil {
v.SetError("LastReply", "admin.not_found_by_id")
}
user.Id = form.LastAuthor
if user.Read() != nil {
v.SetError("LastReply", "admin.not_found_by_id")
}
topic := models.Topic{Id: form.Topic}
if topic.Read() != nil {
v.SetError("Topic", "admin.not_found_by_id")
}
if len(i18n.GetLangByIndex(form.Lang)) == 0 {
v.SetError("Lang", "Not Found")
}
}
开发者ID:varding,项目名称:wetalk,代码行数:25,代码来源:form.go
示例7: GetUserFromSession
// get user if key exist in session
func GetUserFromSession(user *models.User, sess session.SessionStore) bool {
id := GetUserIdFromSession(sess)
if id > 0 {
u := models.User{Id: id}
if u.Read() == nil {
*user = u
return true
}
}
return false
}
开发者ID:varding,项目名称:wetalk,代码行数:13,代码来源:auth.go
示例8: HasUser
// check if exist user by username or email
func HasUser(user *models.User, username string) bool {
var err error
qs := orm.NewOrm()
if strings.IndexRune(username, '@') == -1 {
user.UserName = username
err = qs.Read(user, "UserName")
} else {
user.Email = username
err = qs.Read(user, "Email")
}
if err == nil {
return true
}
return false
}
开发者ID:varding,项目名称:wetalk,代码行数:16,代码来源:auth.go
示例9: Save
// view for new object save
func (this *UserAdminRouter) Save() {
form := auth.UserAdminForm{Create: true}
if this.ValidFormSets(&form) == false {
return
}
var user models.User
form.SetToUser(&user)
if err := user.Insert(); err == nil {
this.FlashRedirect(fmt.Sprintf("/admin/user/%d", user.Id), 302, "CreateSuccess")
return
} else {
beego.Error(err)
this.Data["Error"] = err
}
}
开发者ID:varding,项目名称:wetalk,代码行数:17,代码来源:admin_user.go
示例10: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:17,代码来源:auth.go
示例11: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:19,代码来源:form.go
示例12: Comments
func (this *UserRouter) Comments() {
this.TplNames = "user/comments.html"
var user models.User
if this.getUser(&user) {
return
}
limit := 20
qs := user.RecentComments()
nums, _ := qs.Count()
pager := this.SetPaginator(limit, nums)
var comments []*models.Comment
qs.Limit(limit, pager.Offset()).RelatedSel().All(&comments)
this.Data["TheUserComments"] = comments
}
开发者ID:varding,项目名称:wetalk,代码行数:20,代码来源:user.go
示例13: FavoritePosts
func (this *UserRouter) FavoritePosts() {
this.TplNames = "user/favorite-posts.html"
var user models.User
if this.getUser(&user) {
return
}
var postIds orm.ParamsList
var posts []models.Post
nums, _ := user.FavoritePosts().OrderBy("-Created").ValuesFlat(&postIds, "Post")
if nums > 0 {
qs := models.Posts().Filter("Id__in", postIds)
cnt, _ := models.CountObjects(qs)
pager := this.SetPaginator(setting.PostCountPerPage, cnt)
qs = qs.OrderBy("-Created").Limit(setting.PostCountPerPage, pager.Offset()).RelatedSel()
models.ListObjects(qs, &posts)
}
this.Data["TheUserFavoritePosts"] = posts
}
开发者ID:varding,项目名称:wetalk,代码行数:21,代码来源:user.go
示例14: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:23,代码来源:user.go
示例15: Home
func (this *UserRouter) Home() {
this.Data["IsUserHomePage"] = true
this.TplNames = "user/home.html"
var user models.User
if this.getUser(&user) {
return
}
//recent posts and comments
limit := 5
var posts []*models.Post
var comments []*models.Comment
user.RecentPosts().Limit(limit).RelatedSel().All(&posts)
user.RecentComments().Limit(limit).RelatedSel().All(&comments)
this.Data["TheUserPosts"] = posts
this.Data["TheUserComments"] = comments
//follow topics
var ftopics []*models.FollowTopic
var topics []*models.Topic
ftNums, _ := models.FollowTopics().Filter("User", &user.Id).Limit(8).OrderBy("-Created").RelatedSel("Topic").All(&ftopics, "Topic")
if ftNums > 0 {
topics = make([]*models.Topic, 0, ftNums)
for _, ft := range ftopics {
topics = append(topics, ft.Topic)
}
}
this.Data["TheUserFollowTopics"] = topics
this.Data["TheUserFollowTopicsMore"] = ftNums >= 8
//favorite posts
var favPostIds orm.ParamsList
var favPosts []models.Post
favNums, _ := user.FavoritePosts().Limit(8).OrderBy("-Created").ValuesFlat(&favPostIds, "Post")
if favNums > 0 {
qs := models.Posts().Filter("Id__in", favPostIds)
qs = qs.OrderBy("-Created").RelatedSel()
models.ListObjects(qs, &favPosts)
}
this.Data["TheUserFavoritePosts"] = favPosts
this.Data["TheUserFavoritePostsMore"] = favNums >= 8
}
开发者ID:varding,项目名称:wetalk,代码行数:47,代码来源:user.go
示例16: 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")
}
开发者ID:varding,项目名称:wetalk,代码行数:6,代码来源:auth.go
示例17: 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
}
开发者ID:varding,项目名称:wetalk,代码行数:76,代码来源:auth.go
示例18: getFollows
func (this *UserRouter) getFollows(user *models.User, following bool) []map[string]interface{} {
limit := 20
var qs orm.QuerySeter
if following {
qs = user.FollowingUsers()
} else {
qs = user.FollowerUsers()
}
nums, _ := qs.Count()
pager := this.SetPaginator(limit, nums)
qs = qs.Limit(limit, pager.Offset())
var follows []*models.Follow
if following {
qs.RelatedSel("FollowUser").All(&follows, "FollowUser")
} else {
qs.RelatedSel("User").All(&follows, "User")
}
if len(follows) == 0 {
return nil
}
ids := make([]int, 0, len(follows))
for _, follow := range follows {
if following {
ids = append(ids, follow.FollowUser.Id)
} else {
ids = append(ids, follow.User.Id)
}
}
var eids orm.ParamsList
this.User.FollowingUsers().Filter("FollowUser__in", ids).ValuesFlat(&eids, "FollowUser__Id")
var fids map[int]bool
if len(eids) > 0 {
fids = make(map[int]bool)
for _, id := range eids {
tid, _ := utils.StrTo(utils.ToStr(id)).Int()
if tid > 0 {
fids[tid] = true
}
}
}
users := make([]map[string]interface{}, 0, len(follows))
for _, follow := range follows {
IsFollowed := false
var u *models.User
if following {
u = follow.FollowUser
} else {
u = follow.User
}
if fids != nil {
IsFollowed = fids[u.Id]
}
users = append(users, map[string]interface{}{
"User": u,
"IsFollowed": IsFollowed,
})
}
return users
}
开发者ID:varding,项目名称:wetalk,代码行数:72,代码来源:user.go
示例19: SaveAvatarType
//set a new avatar type to user
func SaveAvatarType(user *models.User, avatarType int) error {
user.AvatarType = avatarType
return user.Update("AvatarType", "Updated")
}
开发者ID:varding,项目名称:wetalk,代码行数:5,代码来源:auth.go
示例20: 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")
}
}
}
开发者ID:varding,项目名称:wetalk,代码行数:18,代码来源:util.go
注:本文中的github.com/varding/wetalk/modules/models.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论