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 --- main.go | 3 +- route/routes/boardmgmt.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++- views/404.html | 10 +++--- 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index ced0485..66ecb6c 100644 --- a/main.go +++ b/main.go @@ -76,12 +76,11 @@ func main() { app.Get("/delete", routes.BoardDelete) app.Get("/deleteattach", routes.BoardDeleteAttach) app.Get("/marksensitive", routes.BoardMarkSensitive) - app.Get("/remove", routes.BoardRemove) app.Get("/addtoindex", routes.BoardAddToIndex) app.Get("/poparchive", routes.BoardPopArchive) app.Get("/autosubscribe", routes.BoardAutoSubscribe) app.Get("/blacklist", routes.BoardBlacklist) - app.Get("/report", routes.BoardReport) + app.All("/report", routes.BoardReport) // Webfinger routes app.Get("/.well-known/webfinger", routes.Webfinger) 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) } diff --git a/views/404.html b/views/404.html index 4be77e5..5af153e 100644 --- a/views/404.html +++ b/views/404.html @@ -1,7 +1,7 @@
-- cgit v1.2.3