Exemplo n.º 1
0
Arquivo: user.go Projeto: zeuson/wego
func (this *UserRouter) getUser(user *models.User) bool {
	username := this.Params().Get(":username")
	user.UserName = username

	u, err := models.GetUserByName(username)
	if err != nil {
		this.NotFound()
		return true
	}
	*user = *u

	IsFollowed := false

	if this.IsLogin {
		if this.User.Id != user.Id {
			IsFollowed = models.IsExist(&models.Follow{
				UserId:       this.User.Id,
				FollowUserId: user.Id,
			})
		}
	}

	this.Data["TheUser"] = &user
	this.Data["IsFollowed"] = IsFollowed

	return false
}
Exemplo n.º 2
0
func LoginUserFromRememberCookie(user *models.User, ctx *tango.Context, session *session.Session) (success bool) {
	userName := GetCookie(ctx.Req(), setting.CookieUserName)
	if len(userName) == 0 {
		return false
	}

	defer func() {
		if !success {
			DeleteRememberCookie(ctx)
		}
	}()

	var err error
	if user, err = models.GetUserByName(userName); err != nil {
		return false
	}

	secret := utils.EncodeMd5(user.Rands + user.Password)
	value, _ := GetSecureCookie(ctx.Req(), secret, setting.CookieRememberName)
	if value != userName {
		return false
	}

	LoginUser(user, ctx, session, true)

	return true
}
Exemplo n.º 3
0
func FilterCommentMentions(fromUser *models.User, post *models.Post, comment *models.Comment) {
	var uri = fmt.Sprintf("post/%d", post.Id)
	var lang = setting.DefaultLang
	if fromUser.Id != post.UserId {
		var notification = models.Notification{
			FromUserId:   fromUser.Id,
			ToUserId:     post.UserId,
			Action:       setting.NOTICE_TYPE_COMMENT,
			Title:        post.Title,
			TargetId:     post.Id,
			Uri:          uri,
			Lang:         lang,
			Floor:        comment.Floor,
			Content:      comment.Message,
			ContentCache: comment.MessageCache,
			Status:       setting.NOTICE_UNREAD,
		}
		if err := models.InsertNotification(&notification); err == nil {
			//pass
		}
	}

	//check comment @
	var pattern = "[ ]*@[a-zA-Z0-9]+[ ]*"
	r := regexp.MustCompile(pattern)
	userNames := r.FindAllString(comment.Message, -1)
	for _, userName := range userNames {
		bUserName := strings.TrimPrefix(strings.TrimSpace(userName), "@")

		if user, err := models.GetUserByName(bUserName); err == nil {
			if user.Id != 0 && user.Id != post.UserId {
				notification := models.Notification{
					FromUserId:   fromUser.Id,
					ToUserId:     user.Id,
					Action:       setting.NOTICE_TYPE_COMMENT,
					Title:        post.Title,
					TargetId:     post.Id,
					Uri:          uri,
					Lang:         lang,
					Floor:        comment.Floor,
					Content:      comment.Message,
					ContentCache: comment.MessageCache,
					Status:       setting.NOTICE_UNREAD,
				}
				if err := models.InsertNotification(&notification); err == nil {
					//pass
				}
			}
		}
	}
}
Exemplo n.º 4
0
// 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 u, err := models.GetUserByName(string(b)); err == nil {
			*user = *u
			return true
		}
	}

	return false
}