示例#1
0
// 删除link
func link_ajaxDel(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	if err == nil {
		user := ctx.Data["user"].(*models.User)
		link, err := models.Link_GetById(linkId)
		if err == nil {
			// 只可以删除自己的链接
			if link.UserId == user.Id {
				err = models.Link_DelById(linkId)
				if err == nil {
					ok = true
				}
			} else {
				errs = "不允许的操作"
			}
		}
	}

	if err != nil {
		errs = err.Error()
	}

	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}
示例#2
0
// 删除link
func admin_del_links(ctx *goku.HttpContext) goku.ActionResulter {
	var errs string
	var ok = false

	linkId, err := strconv.ParseInt(ctx.Get("id"), 10, 64)
	if err == nil {
		err = models.Link_DelById(linkId)
	}

	if err != nil {
		errs = err.Error()
	} else {
		ok = true
	}
	r := map[string]interface{}{
		"success": ok,
		"errors":  errs,
	}

	return ctx.Json(r)
}