当前位置: 首页>>代码示例>>Golang>>正文


Golang models.User类代码示例

本文整理汇总了Golang中github.com/beego/wetalk/modules/models.User的典型用法代码示例。如果您正苦于以下问题:Golang User类的具体用法?Golang User怎么用?Golang User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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:wildex,项目名称:wetalk,代码行数:27,代码来源:auth.go

示例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
	}
}
开发者ID:netxfly,项目名称:wetalk,代码行数:29,代码来源:auth.go

示例3: 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:netxfly,项目名称:wetalk,代码行数:29,代码来源:auth.go

示例4: Home

func (this *UserRouter) Home() {
	this.TplName = "user/home.html"

	var user models.User
	if this.getUser(&user) {
		return
	}

	limit := 5

	var posts []*models.Post
	var comments []*models.Comment

	user.RecentPosts().Limit(limit).RelatedSel().All(&posts)
	user.RecentComments().Limit(limit).RelatedSel().All(&comments)

	var ftopics []*models.FollowTopic
	var topics []*models.Topic
	nums, _ := models.FollowTopics().Filter("User", &user.Id).Limit(8).OrderBy("-Created").RelatedSel("Topic").All(&ftopics, "Topic")
	if nums > 0 {
		topics = make([]*models.Topic, 0, nums)
		for _, ft := range ftopics {
			topics = append(topics, ft.Topic)
		}
	}
	this.Data["TheUserTopics"] = topics
	this.Data["TheUserTopicsMore"] = nums >= 8

	this.Data["TheUserPosts"] = posts
	this.Data["TheUserComments"] = comments
}
开发者ID:wildex,项目名称:wetalk,代码行数:31,代码来源:user.go

示例5: 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:netxfly,项目名称:wetalk,代码行数:7,代码来源:auth_social.go

示例6: 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:netxfly,项目名称:wetalk,代码行数:34,代码来源:auth.go

示例7: 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")
	}

	cat := models.Category{Id: form.Category}
	if cat.Read() != nil {
		v.SetError("Category", "admin.not_found_by_id")
	}

	if len(i18n.GetLangByIndex(form.Lang)) == 0 {
		v.SetError("Lang", "Not Found")
	}
}
开发者ID:oyoy8629,项目名称:XWetalk,代码行数:30,代码来源:form.go

示例8: 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
}
开发者ID:wildex,项目名称:wetalk,代码行数:13,代码来源:auth.go

示例9: 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:wildex,项目名称:wetalk,代码行数:16,代码来源:auth.go

示例10: 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:JessonChan,项目名称:wetalk,代码行数:17,代码来源:admin_user.go

示例11: 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:wildex,项目名称:wetalk,代码行数:17,代码来源:auth.go

示例12: 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:JessonChan,项目名称:wetalk,代码行数:19,代码来源:form.go

示例13: 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:netxfly,项目名称:wetalk,代码行数:20,代码来源:user.go

示例14: 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:netxfly,项目名称:wetalk,代码行数:21,代码来源:user.go

示例15: 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:netxfly,项目名称:wetalk,代码行数:23,代码来源:user.go


注:本文中的github.com/beego/wetalk/modules/models.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。