Exemplo n.º 1
0
func UsersCreate(ctx banana.Context) error {
	r := ctx.Req()

	err := Auth(ctx, PrivilegeUserWrite)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		return err
	case nil:
	default:
		return err
	}

	username, pwd := r.FormValue("username"), r.FormValue("pwd")

	p, err := strconv.ParseInt(r.FormValue("privilege"), 10, 32)
	if err != nil {
		return err
	}
	privilege := int(p) & (PrivilegePostDelete | PrivilegePostDelete | PrivilegePostWrite | PrivilegeUserDelete | PrivilegeUserRead | PrivilegeUserWrite | PrivilegeCategoryRead | PrivilegeCategoryWrite | PrivilegeCategoryDelete)

	err = user.Add(username, pwd, privilege)
	if err != nil {
		return err
	}

	return ctx.Json(struct{}{})
}
Exemplo n.º 2
0
func SaveNewPost(ctx banana.Context) error {

	err := Auth(ctx, PrivilegePostWrite)
	switch err {
	case ErrNoPermit:
		return err
	case ErrNotLogin:
		return err
	case nil:
	default:
		return err
	}

	r := ctx.Req()
	cid, err := strconv.ParseInt(r.FormValue("category"), 10, 32)
	if err != nil {
		return err
	}

	p := post.New()
	p.Title = r.FormValue("title")
	p.Content = r.FormValue("content")
	p.Category.Id = int(cid)
	p.Description = r.FormValue("description")
	p.Keywords.Parse(r.FormValue("keywords"))
	err = p.Save()
	if err != nil {
		return err
	}

	return ctx.Json(p)
}