func (tf *RequireLoginFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) { if u, ok := ctx.Data["user"]; !ok || u == nil { if ctx.IsAjax() { ar = ctx.Json(map[string]interface{}{ "success": false, "needLogin": true, "errors": "请先登陆", }) } else { ar = ctx.Redirect("/user/login?returnurl=" + url.QueryEscape(ctx.Request.RequestURI)) } } return }
// 检查用户的状态(禁言、封号等) func checkUserStatus(user *models.User, ctx *goku.HttpContext) (ar goku.ActionResulter, err error) { if user != nil && user.IsBaned() { if ctx.Request.Method == "POST" { if ctx.IsAjax() { ar = ctx.Json(map[string]interface{}{ "success": false, "needLogin": false, "errors": "你已经被禁言。", }) } else { ctx.ViewData["errorMsg"] = "你已经被禁言" ar = ctx.Render("error", nil) } } } return }
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) } } return }
func (tf *AjaxFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) { if !ctx.IsAjax() { return ctx.Raw("Not AJAX"), nil } return nil, nil }