Example #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)

}
Example #2
0
func apiError(ctx *web.Context, message string) {
	response := ApiResponse{
		Ok:     false,
		Result: message,
	}
	ctx.Write(toJson(response))
}
Example #3
0
func jsonModule(ctx *web.Context) {
	// Lets set the response content type while
	// we are here
	ctx.ContentType("json")
}