func Comment(ctx *middleware.Context) { id := ParseInt(ctx.R.PostFormValue("blogId")) name := ctx.R.PostFormValue("name") email := ctx.R.PostFormValue("email") www := ctx.R.PostFormValue("www") content := ctx.R.PostFormValue("content") blog := model.Blog{Id: id} if exist, err := blog.Exist(); exist { PanicIf(err) comment := model.Comment{Blog: model.Blog{Id: id}, Name: name, Email: email, Www: www, Content: content} if comment.Content == "" { ctx.Set("success", false) ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.submit.failed")) } else if blog.ForbidComment { ctx.Set("success", false) ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.forbid.comment")) } else { comment.Ip = GetRemoteIp(ctx.R) err := comment.Insert() PanicIf(err) ctx.Set("success", true) ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.submit.success")) } } else { ctx.Set("success", false) ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.blog.not.exists")) } ctx.JSON(200, ctx.Response) }