Beispiel #1
0
// 生成token
func (this *TokenService) NewToken(userId string, email string, tokenType int) string {
	token := info.Token{UserId: bson.ObjectIdHex(userId), Token: NewGuidWith(email), CreatedTime: time.Now(), Email: email, Type: tokenType}

	if db.Upsert(db.Tokens, bson.M{"_id": token.UserId}, token) {
		return token.Token
	}

	return ""
}
Beispiel #2
0
func (this *TagService) AddTags(userId string, tags []string) bool {
	for _, tag := range tags {
		if !db.Upsert(db.Tags,
			bson.M{"_id": bson.ObjectIdHex(userId)},
			bson.M{"$addToSet": bson.M{"Tags": tag}}) {
			return false
		}
	}
	return true
}
Beispiel #3
0
// 修改之
func (this *BlogService) UpdateUserBlog(userBlog info.UserBlog) bool {
	return db.Upsert(db.UserBlogs, bson.M{"_id": userBlog.UserId}, userBlog)
}