示例#1
0
func (raf *RequireAdminFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	ar, err = raf.RequireLoginFilter.OnActionExecuting(ctx)
	if ar != nil || err != nil {
		return
	}
	user := ctx.Data["user"].(*models.User)
	if !user.IsAdmin() {
		if ctx.IsAjax() {
			ar = ctx.Json(map[string]interface{}{
				"success":   false,
				"needLogin": false,
				"errors":    "没有权限",
			})
		} else {
			// ctx.ViewData["errorMsg"] = "没有权限"
			// ar = ctx.Render("error", nil)
			ar = ctx.Raw("没有权限")
		}
	}
	return
}
示例#2
0
文件: ajax.go 项目: yonglehou/ohlala
func (tf *AjaxFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	if !ctx.IsAjax() {
		return ctx.Raw("Not AJAX"), nil
	}
	return nil, nil
}