Exemplo n.º 1
0
func getResponseHelper(req *wcg.Request) ResponseHelper {
	app := req.Local(LOCAL_APP_KEY).(*App)
	if strings.HasPrefix(req.URL().Path, "/api") {
		return app.Api
	}
	return app.Page
}
Exemplo n.º 2
0
// HTTP 201 Created
func (api *ApiHelper) Created(res *wcg.Response, req *wcg.Request, id string) {
	loc := path.Join(req.URL().Path, fmt.Sprintf("%s.json", id))
	res.WriteJsonWithStatus(201, nil, map[string]interface{}{
		"ok":       true,
		"id":       id,
		"location": wcg.AbsoluteUrl(req, loc),
	})
}
Exemplo n.º 3
0
func (ph *PageHelper) Forbidden(res *wcg.Response, req *wcg.Request) {
	res.SetLocal("Ref", req.URL().RequestURI())
	res.TemplatesWithStatus(
		403,
		nil,
		"403.html", "header.html", "footer.html",
	)
}
Exemplo n.º 4
0
func ahAuthHandler(res *wcg.Response, req *wcg.Request) bool {
	if strings.HasPrefix(req.URL().Path, "/_ah/") {
		req.User = &ApiUser{
			token: &models.ApiToken{
				Token:       "x-appengine-ah",
				Description: "Dummy API Token (_ah user)",
				CreatedAt:   time.Now(),
			},
			lastLogin: time.Now(),
		}
		return true
	}
	return false
}
Exemplo n.º 5
0
func showBlogHandler(res *wcg.Response, req *wcg.Request) {
	blog, posts, err := fetchBlog(res, req, true)
	if err != nil {
		return
	}
	res.SetLocal("Og", &supports.Og{Title: blog.Title,
		Type: "blog", Url: wcg.AbsoluteUrl(req, req.URL().Path),
		Description: blog.Description, SiteName: AppConfig.SiteTitle,
	})
	res.SetLocal("blog", blog)
	res.SetLocal("is_owner", blog.OwnerId == req.User.Id())
	res.SetLocal("posts", posts)
	res.SetLocal("js", "/static/js/blog.js")
	res.Templates("blog.html", "header.html", "footer.html", "parts/post_part.html")
}
Exemplo n.º 6
0
func (p *Page) _processRequest(res *wcg.Response, req *wcg.Request) {
	// instance of Page
	pi := &Page{}
	pi.App = p.App
	pi.Title = p.Title
	pi.Path = p.Path
	pi.assetPath = p.assetPath
	if p.templates != nil {
		pi.templates = make([]string, len(p.templates))
		for i := range p.templates {
			pi.templates[i] = p.templates[i]
		}
	}
	pi.Ogp("site_name", "SPEEDLAND Project")
	// pre process to update page attributes
	if p.handler != nil {
		p.handler(res, req, pi)
		if res.IsClosed() {
			return
		}
	}

	// automatically set ogp attributes if not set.
	if _, ok := pi.ogp["title"]; !ok {
		pi.Ogp("title", fmt.Sprintf("%s: %s", pi.App.Title, pi.Title))
	}
	if _, ok := pi.ogp["url"]; !ok {
		pi.Ogp("url", wcg.AbsoluteUrl(req, req.URL().RequestURI()))
	}

	// set default OGP from app settings.
	for k, v := range pi.App.DefaultOgp {
		pi.Ogp(k, v)
	}

	res.SetLocal("Page", pi)
	res.SetLocal("Ogp", pi.ogp)
	res.SetLocal("Request", req)
	res.SetLocal("TrackingCode", TrackingCode)
	res.SetLocal("__JsBundle__", pi.GetAssetPath())
	res.SetLocal("__APP_COMMIT", APP_COMMIT)
	res.SetLocal("__APP_TIMESTAMP", APP_TIMESTAMP)
	template_paths := []string{"./header.html", "./footer.html"}
	res.Templates(append(pi.GetTemplates(), template_paths...)...)
}
Exemplo n.º 7
0
func showPostHandler(res *wcg.Response, req *wcg.Request) {
	blog, _, err := fetchBlog(res, req, false)
	if err != nil {
		return
	}
	post, err := fetchPost(res, req, blog)
	if err != nil {
		return
	}
	res.SetLocal("Og", &supports.Og{Title: post.Title, Type: "article",
		Url: wcg.AbsoluteUrl(req, req.URL().Path), SiteName: blog.Title,
		Description: wcg.Shorten(post.Content, 80),
	})
	res.SetLocal("blog", blog)
	res.SetLocal("post", post)
	res.SetLocal("is_owner", post.OwnerId == req.User.Id())
	res.SetLocal("js", "/static/js/post.js")
	res.Templates("post.html", "header.html", "footer.html", "parts/post_part.html")
}