Exemplo 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)
	}
}
Exemplo 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)
		}
	}
}
Exemplo n.º 3
0
		if u, ok := ctx.Data["user"]; ok && u != nil {
			return ctx.Redirect("/")
		}
		ctx.ViewData["query"] = template.URL(ctx.Request.URL.RawQuery)
		ctx.ViewData["key"] = ctx.Get("key")
		ctx.ViewData["InviteEnabled"] = golink.Invite_Enabled

		return ctx.Render("login", nil)
	}).

	/**
	 * logout
	 */
	Get("logout", func(ctx *goku.HttpContext) goku.ActionResulter {

		redisClient := models.GetRedis()
		defer redisClient.Quit()
		redisClient.Del("_glut")
		c := &http.Cookie{
			Name:    "_glut",
			Expires: time.Now().Add(-10 * time.Second),
			Path:    "/",
		}
		ctx.SetCookie(c)
		return ctx.Redirect("/")
	}).

	/**
	 * login
	 */
	Post("login", func(ctx *goku.HttpContext) goku.ActionResulter {