From 3ac22385f2cb2256db718e47f5ae3c6d13353b70 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 5 Jun 2022 15:14:34 -0700 Subject: added janny managment for admin board pages --- activitypub/actor.go | 72 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) (limited to 'activitypub') diff --git a/activitypub/actor.go b/activitypub/actor.go index ea4ff3b..c6283c8 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -839,12 +839,10 @@ func (actor Actor) ReportedResp(ctx *fiber.Ctx) error { return util.MakeError(err, "GetReported") } - if hasAuth, err := util.HasAuth(verification[1], actor.Id); !hasAuth { + if hasAuth, _ := util.HasAuth(verification[1], actor.Id); !hasAuth { ctx.Response().Header.SetStatusCode(http.StatusBadRequest) _, err := ctx.Write([]byte("")) return util.MakeError(err, "GetReported") - } else if err != nil { - return util.MakeError(err, "GetReported") } actor, err = GetActorFromDB(actor.Id) @@ -1099,3 +1097,71 @@ func (actor Actor) WantToServePage(page int) (Collection, error) { return collection, nil } + +func (actor Actor) CreateVerification(verify util.Verify) error { + var err error + + if verify.Code, err = util.CreateKey(50); err != nil { + return util.MakeError(err, "CreateVerification") + } + + if err := verify.Create(); err != nil { + return util.MakeError(err, "CreateVerification") + } + + verify.Board = actor.Id + verify.Identifier = verify.Type + + if err := verify.CreateBoardMod(); err != nil { + return util.MakeError(err, "CreateVerification") + } + + return nil +} + +func (actor Actor) DeleteVerification(verify util.Verify) error { + query := `delete from boardaccess where code=$1` + if _, err := config.DB.Exec(query, verify.Code); err != nil { + return util.MakeError(err, "DeleteVerification") + } + + var code string + query = `select verificationcode from crossverification where code=$1` + if err := config.DB.QueryRow(query, verify.Code).Scan(&code); err != nil { + return util.MakeError(err, "DeleteVerification") + } + + query = `delete from crossverification where code=$1` + if _, err := config.DB.Exec(query, verify.Code); err != nil { + return util.MakeError(err, "DeleteVerification") + } + + query = `delete from verification where code=$1` + if _, err := config.DB.Exec(query, code); err != nil { + return util.MakeError(err, "DeleteVerification") + } + + return nil +} + +func (actor Actor) GetJanitors() ([]util.Verify, error) { + var list []util.Verify + + query := `select identifier, code, board, type, label from boardaccess where board=$1 and type='janitor'` + rows, err := config.DB.Query(query, actor.Id) + + if err != nil { + return list, util.MakeError(err, "GetJanitors") + } + + defer rows.Close() + for rows.Next() { + var verify util.Verify + + rows.Scan(&verify.Identifier, &verify.Code, &verify.Board, &verify.Type, &verify.Label) + + list = append(list, verify) + } + + return list, nil +} -- cgit v1.2.3