예제 #1
0
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)
}
예제 #2
0
func DeleteComment(ctx *middleware.Context, params martini.Params) {
	blogId := ParseInt(params["blogId"])
	seq := ParseInt(params["seq"])
	comment := model.Comment{Blog: model.Blog{Id: blogId}, Seq: seq}

	err := comment.Delete()
	if err != nil {
		ctx.Set("success", false)
		ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.error.delete.failed"))
	} else {
		ctx.Set("success", true)
		ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.delete.success"))
	}
	ctx.JSON(200, ctx.Response)
}