Exemplo n.º 1
0
func cookieModule(ctx *web.Context) {
	// Fail early if we are only logging on
	path := ctx.Request.URL.String()
	if strings.Contains(path, "/login") {
		return
	}

	// Pull out the user data from the cookie
	// and set the session
	cookie, success := ctx.GetSecureCookie("session")
	if !success {
		ctx.Server.Logger.Println("Session cookie is invalid")
		apiError(ctx, "Invalid session cookie")
		return
	}

	if cookie == "" {
		apiError(ctx, "Corrupt user data")
		return
	}

	user := new(User)
	json.Unmarshal([]byte(cookie), user)
	ctx.User = (*user)

}