예제 #1
0
파일: post.go 프로젝트: hjin-me/HJinBlog
func Post(ctx banana.Context) error {
	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	var (
		idStr string
		ok    bool
	)
	if idStr, ok = ctx.Params()["id"]; !ok {
		panic("no id")
	}
	id, err := strconv.ParseInt(idStr, 10, 32)
	if err != nil {
		panic(err)
	}
	p := post.ReadRaw(int(id))
	categories, err := category.Query()
	if err != nil {
		return err
	}

	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
	return ctx.Tpl(theme.CP("layout"), layout)
}
예제 #2
0
파일: post.go 프로젝트: hjin-me/HJinBlog
func NewPost(ctx banana.Context) error {
	err := Auth(ctx, PrivilegePostRead)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		http.Redirect(ctx.Res(), ctx.Req(), "/login?error", http.StatusFound)
		return nil
	case nil:
	default:
		return err
	}

	categories, err := category.Query()
	if err != nil {
		return err
	}

	p := post.New()
	layout := ThemeLayout{}
	layout.Content = ThemeBlock{theme.CP("post"), struct{ Post, Categories interface{} }{p, categories}}
	return ctx.Tpl(theme.CP("layout"), layout)
}