From c5d1ab0266f7e478206df26df540c163b2faf757 Mon Sep 17 00:00:00 2001 From: Ro Date: Mon, 16 Jan 2023 20:17:22 -0800 Subject: [PATCH] Added Front listings and member editing Added the template for to display locations on the front end. Still need to add template for individual locations. Also added member editing. Still need to wire up the avatar uploading but adding and editing member information is possible. Still need to fine tune it according to roles --- public/assets/css/back/index.css | 11 +- public/assets/css/back/locations.css | 5 +- public/assets/css/back/members.css | 7 ++ public/assets/css/back/start.css | 1 + public/assets/css/front/about.css | 2 +- public/assets/css/front/listing.css | 3 +- src/Controller/Routes/Back/Members.php | 133 +++++++++++++------------ src/Service/HandleMembers.php | 95 ++++++++++++++---- templates/back/members.twig | 31 +++++- templates/base/frame.twig | 2 +- templates/forms/add-member-form.twig | 3 +- templates/forms/edit-member.twig | 80 +++++++++++++++ templates/front/about.twig | 22 ++-- 13 files changed, 291 insertions(+), 104 deletions(-) create mode 100644 public/assets/css/back/members.css create mode 100644 templates/forms/edit-member.twig diff --git a/public/assets/css/back/index.css b/public/assets/css/back/index.css index 6d28bfa..e3b1f0f 100644 --- a/public/assets/css/back/index.css +++ b/public/assets/css/back/index.css @@ -1,6 +1,8 @@ section[role="den-login"] { - padding: 30px; - width: 300px; + width: 100%; + max-width: 600px; + padding: 10px; + margin: 0 auto; color: var(--highlight); } @@ -12,7 +14,10 @@ section[role="den-login"] div[role="system-notice"] { } section[role="den-index"] { - padding: 20px; + width: 100%; + max-width: 600px; + padding: 10px; + margin: 0 auto; color: var(--white); } diff --git a/public/assets/css/back/locations.css b/public/assets/css/back/locations.css index 65c6132..1995019 100644 --- a/public/assets/css/back/locations.css +++ b/public/assets/css/back/locations.css @@ -1,5 +1,8 @@ section[role="loc-index"] { - padding: 20px; + width: 100%; + max-width: 600px; + padding: 10px; + margin: 0 auto; } section[role="loc-index"] img { diff --git a/public/assets/css/back/members.css b/public/assets/css/back/members.css new file mode 100644 index 0000000..ee53b0d --- /dev/null +++ b/public/assets/css/back/members.css @@ -0,0 +1,7 @@ +section[role="members-index"] { + width: 100%; + max-width: 600px; + padding: 10px; + margin: 0 auto; + color: var(--white); +} diff --git a/public/assets/css/back/start.css b/public/assets/css/back/start.css index 2c75d82..cfa6f84 100644 --- a/public/assets/css/back/start.css +++ b/public/assets/css/back/start.css @@ -4,4 +4,5 @@ @import "../global/frame.css"; @import "../global/icons.css"; @import "locations.css"; +@import "members.css"; @import "index.css"; diff --git a/public/assets/css/front/about.css b/public/assets/css/front/about.css index 3b0fd1b..7605ad2 100644 --- a/public/assets/css/front/about.css +++ b/public/assets/css/front/about.css @@ -2,7 +2,7 @@ section[role="about"] { background: var(--primary); width: 100%; max-width: 600px; - padding: 100px; + padding: 10px; margin: 0 auto; color: var(--white); } diff --git a/public/assets/css/front/listing.css b/public/assets/css/front/listing.css index b629c8e..a2db055 100644 --- a/public/assets/css/front/listing.css +++ b/public/assets/css/front/listing.css @@ -2,8 +2,7 @@ section[role="listings"] { background: var(--primary); width: 100%; max-width: 600px; - border-radius: 3px; - padding: 100px; + padding: 10px; margin: 0 auto; color: var(--white); } diff --git a/src/Controller/Routes/Back/Members.php b/src/Controller/Routes/Back/Members.php index 875b9ee..19243ae 100644 --- a/src/Controller/Routes/Back/Members.php +++ b/src/Controller/Routes/Back/Members.php @@ -9,58 +9,66 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Doctrine\Persistence\ManagerRegistry; -//use App\Utils\PageRender; -//use App\Utils\StringTools; -use App\Service\Auth; use App\Service\HandleMembers; +use App\Service\Render; +use App\Service\Auth; class Members extends AbstractController { /** - * @Route("/dashboard/members", name="dash-members") + * @Route("/den/members/page/{pageNum}", name="den-locations") */ public function showMembers( Request $request, - Auth $auth - ): Response { + Auth $auth, + Render $render, + HandleMembers $members, + int $pageNum = 1 + ) { $result = $auth->status(); if ($result["status"]) { - /* - return $render->renderPage( - ["bgImage" => "", "mode" => "index"], - "The Nile List | Members", - "dash/members.html.twig" - ); - */ + $self = $members->getYou(); + $you = $self->getId(); + $list = $members->getMemberPage($pageNum); + + return $render->page([ + "mode" => "index", + "you" => $you, + "list" => $list], "Bad Space | Members", "back/members.twig"); } else { - //back to index to login - header("Location:/knockknock"); - return new Response("LOGGED IN"); } } /** - * @Route("/den/members/add", name="members-add") - */ - public function addMembers( + * @Route("/den/members/{action}/{id}", name="den-members") + */ + public function handleMemberActions( Request $request, Auth $auth, + Render $render, HandleMembers $members, - ManagerRegistry $doctrine + string $action = "index", + int $id = 0 ): Response { $result = $auth->status(); if ($result["status"]) { if ($request->getMethod() == "GET") { - return $this->render("back/members.twig", [ - "title" => "Get a class from the cupboard", - "mode" => "add" - ]); + $self = $members->getYou(); + $you = $self->getId(); + $member = []; + if ($id != 0) { + $member = $members->getMemberById($id); + } + return $render->page([ + "mode" => $action, + "you" => $you, + "currentMember" => $member], "Bad Space | Members", "back/members.twig"); } else { //add new member - $token = $request->get("token"); - $notice = ""; - $entityManager = $doctrine->getManager(); + $token = $request->get("token"); + $notice = ""; + $mode = $request->get("mode"); + $id = $request->get("member_id"); //token check if (!$this->isCsrfTokenValid("upload", $token)) { @@ -74,7 +82,12 @@ class Members extends AbstractController ] ); } - + $self = $members->getYou(); + $you = $self->getId(); + $member = []; + if ($id != 0) { + $member = $members->getMemberById($id); + } if ( $request->request->get("handle") == "" || $request->request->get("role") == "" || @@ -82,48 +95,44 @@ class Members extends AbstractController $request->request->get("email") == "" || $request->request->get("pronoun") == "" ) { - return new Response("All fields required"); - - /* $notice = "All fields are required, champ."; - return $render->renderPage( - ["bgImage" => "", "mode" => "add", "notice" => $notice], - "The Nile List | Add Member Error", - "dash/members.html.twig" - ); - */ + return $render->page([ + "notice" => $notice, + "mode" => $mode, + "you" => $you, + "currentMember" => $member], "Bad Space | Members", "back/members.twig"); } - + //empty valid email check if ( !filter_var($request->request->get("email"), FILTER_VALIDATE_EMAIL) ) { - return new Response("BOGUS EMAIL"); - - /* $notice = "Need a valid email, slick."; - return $render->renderPage( - ["bgImage" => "", "mode" => "add", "notice" => $notice], - "The Nile List | Add Member Error", - "dash/members.html.twig" - ); - */ + return $render->page([ + "notice" => $notice, + "mode" => $mode, + "you" => $you, + "currentMember" => $member], "Bad Space | Members", "back/members.twig"); + } + // password confirm check + if ($request->request->get("new_pass") != "") { + if ($request->request->get("new_pass") != $request->request->get("new_pass_confirm")) { + $notice = "New password must be confirmed"; + return $render->page([ + "notice" => $notice, + "mode" => $mode, + "you" => $you, + "currentMember" => $member], "Bad Space | Members", "back/members.twig"); + } } //check clear, call add method - $response = $members->addMember($request); + $response = $members->modifyMember($request, $id, $mode); if ($response["status"]) { - /* - return $render->renderPage( - [ - "bgImage" => "", - "mode" => "add", - "notice" => $response["message"], - ], - "The Nile List | Add Members", - "dash/members.html.twig" - ); - */ - return new Response("MEMBER ADDED"); + return $render->page([ + "notice" => $response["message"], + "mode" => $mode, + "you" => $you, + "currentMember" => $member], "Bad Space | Members", "back/members.twig"); } else { return new Response("" . $response["message"] . ""); /* @@ -138,7 +147,7 @@ class Members extends AbstractController } else { //back to index to login header("Location:/den"); - return new Response("LOGGED IN"); + return new Response("TO THE FRONT"); } } } diff --git a/src/Service/HandleMembers.php b/src/Service/HandleMembers.php index fbdb70a..e36827f 100644 --- a/src/Service/HandleMembers.php +++ b/src/Service/HandleMembers.php @@ -24,6 +24,7 @@ class HandleMembers { private $session; private $entityManager; + private $limit = 5; public function __construct( EntityManagerInterface $entityManager, @@ -38,22 +39,63 @@ class HandleMembers * * @return MEMBERS data object */ - public function getMember() + public function getYou() { $member = $this->session->get("member"); return $member; } + public function getMemberById(int $id) + { + $member = $this->entityManager->getRepository(Member::class)->find($id); + + return $member; + } + + public function getMemberPage(int $page, string $active = "all") + { + $members = $this->entityManager->getRepository(Member::class); + if ($active == "true" || $active == "false") { + $list = $members->findBy(["active" => $active], ["id" => "ASC"]); + } else { + $list = $members->findBy([], ["id" => "ASC"]); + } + + $count = ceil(count($list) / $this->limit); + $totalCount = count($list); + + $shelf = []; + $range = $page * $this->limit - $this->limit; + for ($i = 0; $i <= $this->limit; $i++) { + try { + array_push($shelf, $list[$i + $range]); + } catch (Exception $error) { + } + } + + return [ + "members" => $shelf, + "total" => $count, + "totalMembers" => $totalCount, + ]; + } + /** - * Add new member to db + * Add or edit new member * * @param Request $request object containing posted data - * @return JSON + * @param int $memberId member identifier + * @param string $action request task + * @return Object */ - public function addMember($request) + public function modifyMember($request, $memberId, $action) { $errorMessage = null; - $member = new Member(); + if ($action == "add") { + $member = new Member(); + } else { + $member = $this->entityManager->getRepository(Member::class)->find($memberId); + } //submitted values $handle = $request->request->get("handle"); @@ -69,15 +111,23 @@ class HandleMembers //set defaults //$utils = new StringTools(); - $uuid = $hash = password_hash("passw0rd!", PASSWORD_DEFAULT); - $member->setPassword($hash); - $member->setAvatar("default-member-avatar"); - $member->setUuid(Uuid::v4()); - $member->setActive(false); - $member->setCreatedAt(new \DateTimeImmutable()); - $member->setLastLogin(new \DateTimeImmutable()); - - $this->entityManager->persist($member); + if ($action == "add") { + $hash = password_hash("passw0rd!", PASSWORD_DEFAULT); + $member->setPassword($hash); + $member->setActive(false); + $member->setAvatar("default-member-avatar"); + $member->setUuid(Uuid::v4()); + $this->entityManager->persist($member); + $member->setCreatedAt(new \DateTimeImmutable()); + $member->setLastLogin(new \DateTimeImmutable()); + } else { + $active = ($request->request->get("active") == "true" ? true : false); + $member->setActive($active); + if ($request->request->get("new_pass") != "") { + $hash = password_hash($request->request->get("new_pass"), PASSWORD_DEFAULT); + $member->setPassword($hash); + } + } try { $this->entityManager->flush(); @@ -93,10 +143,16 @@ class HandleMembers $errorMessage = $error->getMessage(); } // return result status + $message = ""; + if ($action == "add") { + $message = "New member added. Woohoo!"; + } else { + $message = "Member Info Edited"; + } if ($errorMessage == null) { return $response = [ "status" => true, - "message" => "New member added. Woohoo!", + "message" => $message, ]; } else { return $response = ["status" => false, "message" => $errorMessage]; @@ -111,11 +167,10 @@ class HandleMembers */ public function updateMember($request) { - $errorMessage = null; - $currentMember = $this->getMember(); - $id = $currentMember->getMemberId(); - $member = $this->entityManager->getRepository(Members::class)->find($id); - $image = $request->files->get("avi"); + $errorMessage = null; + $id = $request->request->get("member_id"); + $member = $this->entityManager->getRepository(Members::class)->find($id); + $image = $request->files->get("avi"); if (!empty($image)) { $name = $image->getClientOriginalName(); $member->setAvatar($name); diff --git a/templates/back/members.twig b/templates/back/members.twig index 602dc7b..1cadaf1 100644 --- a/templates/back/members.twig +++ b/templates/back/members.twig @@ -4,9 +4,30 @@ {% endblock %} {% block main %} -
- This is the screendoor member page +
- {{ include("forms/add-member-form.twig") }} -
- {% endblock %} + {% if options.mode == "index" %} +

Members

+

Manage member accounts

+ Edit Profile + | + Add Members +

Current Members

+ {% for member in options.list.members %} + {% if member.role != 1 %} + {{ member.handle }} +
+ {% endif %} + + {% endfor %} + {% elseif options.mode == "add" %} +

Add Member

+ {{ include("forms/add-member-form.twig") }} + + {% elseif options.mode == "edit" %} +

Edit Member

+ {{ include("forms/edit-member.twig") }} + {% endif %} + +
+ {% endblock %} diff --git a/templates/base/frame.twig b/templates/base/frame.twig index 5030b97..0d83a0a 100644 --- a/templates/base/frame.twig +++ b/templates/base/frame.twig @@ -30,7 +30,7 @@ - + diff --git a/templates/forms/add-member-form.twig b/templates/forms/add-member-form.twig index d0fc297..36546e8 100644 --- a/templates/forms/add-member-form.twig +++ b/templates/forms/add-member-form.twig @@ -1,4 +1,4 @@ -
+

@@ -33,4 +33,5 @@
+
diff --git a/templates/forms/edit-member.twig b/templates/forms/edit-member.twig new file mode 100644 index 0000000..819a9b3 --- /dev/null +++ b/templates/forms/edit-member.twig @@ -0,0 +1,80 @@ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+ + + +
diff --git a/templates/front/about.twig b/templates/front/about.twig index e889b42..96cc4f8 100644 --- a/templates/front/about.twig +++ b/templates/front/about.twig @@ -5,14 +5,20 @@ {% block main %}
-

About The Bad Space

-

The Bad Space project was born from a need to effectively identify instances that house bad actors and are poorly moderated, which puts marginalized communities at risk. It is an extension of the - #fediblock - hashtag created - by Arist Maricia X - with additional support from - Ginger - to provide a catolog of instances seek to cause harm and reduce the quality of experience in the fediverse. +

About

+ +

What is The Bad Space?

+

The Bad Space project was born from a need to effectively identify instances that house bad actors and are poorly moderated, which puts marginalized communities at risk. +

+ It is an extension of the + #fediblock + hashtag created by + Artist Marcia X + with additional support from + Ginger + to provide a catolog of instances seek to cause harm and reduce the quality of experience in the fediverse. +

+