From fbc0e5e5f910ea64b6b18be1a354817c195a6f04 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 22 May 2022 19:23:40 -0700 Subject: first pass on reporting working - will improve its usability more --- route/routes/boardmgmt.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'route') diff --git a/route/routes/boardmgmt.go b/route/routes/boardmgmt.go index cd09c4f..368e5d1 100644 --- a/route/routes/boardmgmt.go +++ b/route/routes/boardmgmt.go @@ -8,6 +8,7 @@ import ( "github.com/FChannel0/FChannel-Server/activitypub" "github.com/FChannel0/FChannel-Server/config" + "github.com/FChannel0/FChannel-Server/db" "github.com/FChannel0/FChannel-Server/post" "github.com/FChannel0/FChannel-Server/util" "github.com/gofiber/fiber/v2" @@ -351,5 +352,80 @@ func BoardBlacklist(ctx *fiber.Ctx) error { } func BoardReport(ctx *fiber.Ctx) error { - return ctx.SendString("board report") + id := ctx.FormValue("id") + board := ctx.FormValue("board") + reason := ctx.FormValue("comment") + close := ctx.FormValue("close") + + actor, err := activitypub.GetActorByNameFromDB(board) + + if err != nil { + return util.MakeError(err, "BoardReport") + } + _, auth := util.GetPasswordFromSession(ctx) + + var captcha = ctx.FormValue("captchaCode") + ":" + ctx.FormValue("captcha") + + if len(reason) > 100 { + return ctx.Status(403).Render("403", fiber.Map{ + "message": "Report comment limit 100 characters", + }) + } + + if ok, _ := post.CheckCaptcha(captcha); !ok && close != "1" { + return ctx.Status(403).Render("403", fiber.Map{ + "message": "Invalid captcha", + }) + } + + var obj = activitypub.ObjectBase{Id: id} + + if close == "1" { + if auth, err := util.HasAuth(auth, actor.Id); !auth { + config.Log.Println(err) + return ctx.Status(404).Render("404", fiber.Map{ + "message": "Something broke", + }) + } + + if local, _ := obj.IsLocal(); !local { + if err := db.CloseLocalReport(obj.Id, board); err != nil { + config.Log.Println(err) + return ctx.Status(404).Render("404", fiber.Map{ + "message": "Something broke", + }) + } + + return ctx.Redirect("/"+config.Key+"/"+board, http.StatusSeeOther) + } + + if err := obj.DeleteReported(); err != nil { + config.Log.Println(err) + return ctx.Status(404).Render("404", fiber.Map{ + "message": "Something broke", + }) + } + + return ctx.Redirect("/"+config.Key+"/"+board, http.StatusSeeOther) + } + + if local, _ := obj.IsLocal(); !local { + if err := db.CreateLocalReport(id, board, reason); err != nil { + config.Log.Println(err) + return ctx.Status(404).Render("404", fiber.Map{ + "message": "Something broke", + }) + } + + return ctx.Redirect("/"+board+"/"+util.RemoteShort(obj.Id), http.StatusSeeOther) + } + + if err := db.CreateLocalReport(obj.Id, board, reason); err != nil { + config.Log.Println(err) + return ctx.Status(404).Render("404", fiber.Map{ + "message": "Something broke", + }) + } + + return ctx.Redirect(id, http.StatusSeeOther) } -- cgit v1.2.3