Ejemplo n.º 1
0
//为别的平台用户写cookie
func setCookieForOtherPlatformUser(userId int64, email string, seconds int, ctx *goku.HttpContext) {
	//注册成功,写cookie
	now := time.Now()
	h := md5.New()
	h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
	ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
	expires := now.Add(time.Duration(seconds) * time.Second)
	redisClient := models.GetRedis()
	defer redisClient.Quit()
	err := redisClient.Set(ticket, userId)
	if err != nil {
		goku.Logger().Errorln(err.Error())
	} else {
		_, err = redisClient.Expireat(ticket, expires.Unix())
		if err != nil {
			goku.Logger().Errorln(err.Error())
		}
		c := &http.Cookie{
			Name:     "_glut",
			Value:    ticket,
			Expires:  expires,
			Path:     "/",
			HttpOnly: true,
		}
		ctx.SetCookie(c)
	}
}
Ejemplo n.º 2
0
func main() {
	redisClient := models.GetRedis()
	defer redisClient.Quit()
	// 从推送队列取出处理
	for {
		// 格式: pushtype,userid(topicid),linkid,timestamp
		item, err := redisClient.Rpop(golink.KEY_LIST_PUSH_TO_USER)
		if err != nil {
			if strings.Index(err.Error(), "Nonexisting key") < 0 {
				goku.Logger().Errorln(err.Error())
			}
			time.Sleep(30 * time.Second)
		} else if item != nil {
			items := strings.Split(item.String(), ",")
			if len(items) > 1 {
				kid, err := strconv.ParseInt(items[1], 10, 64)
				if err != nil {
					goku.Logger().Errorln(err.Error())
					continue
				}
				linkId, err := strconv.ParseInt(items[2], 10, 64)
				if err != nil {
					goku.Logger().Errorln(err.Error())
					continue
				}
				if items[0] == "1" {
					// 推给粉丝
					err = models.LinkForUser_ToUserFollowers(kid, linkId)
				} else if items[0] == "2" {
					// 推给话题关注者
					err = models.LinkForUser_ToTopicidFollowers(kid, linkId)
				} else {
					goku.Logger().Errorln("值错误:", item.String())
				}
				if err != nil {
					goku.Logger().Errorln(err.Error())
				}
			}
		} else {
			time.Sleep(30 * time.Second)
		}
	}
}
Ejemplo n.º 3
0
			m := f.CleanValues()
			email := strings.ToLower(m["email"].(string))
			// 检查密码是否正确
			userId := models.User_CheckPwd(email, m["pwd"].(string))
			if userId > 0 {
				now := time.Now()
				h := md5.New()
				h.Write([]byte(fmt.Sprintf("%v-%v", email, now.Unix())))
				ticket := fmt.Sprintf("%x_%v", h.Sum(nil), now.Unix())
				var expires time.Time
				if m["remeber_me"] == "1" {
					expires = now.Add(365 * 24 * time.Hour)
				} else {
					expires = now.Add(48 * time.Hour)
				}
				redisClient := models.GetRedis()
				defer redisClient.Quit()
				err := redisClient.Set(ticket, userId)
				if err != nil {
					goku.Logger().Errorln(err.Error())
					errorMsgs = append(errorMsgs, "登陆票据服务器出错,请重试")
				} else {
					_, err = redisClient.Expireat(ticket, expires.Unix())
					if err != nil {
						goku.Logger().Errorln(err.Error())
						errorMsgs = append(errorMsgs, "登陆票据服务器出错,请重试")
					}
					c := &http.Cookie{
						Name:    "_glut",
						Value:   ticket,
						Expires: expires,