aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2022-05-22 19:23:40 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commitfbc0e5e5f910ea64b6b18be1a354817c195a6f04 (patch)
treeda6638be4cce90eb6ff35882ab5d13c8bc20aec5
parent72db74e35577ae857023791ec6cb287b26748727 (diff)
first pass on reporting working - will improve its usability more
-rw-r--r--main.go3
-rw-r--r--route/routes/boardmgmt.go78
-rw-r--r--views/404.html10
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 @@
<div class="box2">
- <h1>404</h1>
-
- <p>
- Click <a href="/">here</a> to return to the index.
- </p>
+ <h1>404</h1>
+ <p>{{ .message }}</p>
+ <p>
+ Click <a href="/">here</a> to return to the index.
+ </p>
</div>