mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-06-25 16:04:37 -05:00
Auth Framework, Part 1
Started buildig the authorization infrastructure to 1. create the initial admin class to then 2. the Auth manager class can be created to manage access based on roles. added number of template files as well just as a UI base to get things started. Auth Framework Part 2 will complete the Auth mangager and clean up the admin area.
This commit is contained in:
44
src/Controller/Routes/Back/Index.php
Normal file
44
src/Controller/Routes/Back/Index.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
// src/Controller/DataImport.php
|
||||
// Grab data from transfer app
|
||||
|
||||
namespace App\Controller\Routes\Back;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
//use App\Utils\PageRender;
|
||||
//use App\Data\Auth;
|
||||
|
||||
class Index extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/screendoor", name="back-index")
|
||||
*/
|
||||
public function showBackIndex(Request $request): Response
|
||||
{
|
||||
return $this->render("back/index.twig", [
|
||||
"title" => "Close the door behind you",
|
||||
]);
|
||||
/*
|
||||
$result = $auth->status();
|
||||
if ($result["status"]) {
|
||||
return $render->renderPage(
|
||||
[
|
||||
"bgImage" => "/images/base/tweed-flowers.png",
|
||||
"role" => $result["role"],
|
||||
],
|
||||
"The Nile List | Welcome Back",
|
||||
"front/index.html.twig"
|
||||
);
|
||||
} else {
|
||||
//back to index to login
|
||||
header("Location:/login");
|
||||
return new Response("<html><body>LOGGED IN</body></html>");
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
144
src/Controller/Routes/Back/Members.php
Normal file
144
src/Controller/Routes/Back/Members.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
// src/Controller/DataImport.php
|
||||
// Grab data from transfer app
|
||||
|
||||
namespace App\Controller\Routes\Back;
|
||||
|
||||
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;
|
||||
|
||||
class Members extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/dashboard/members", name="dash-members")
|
||||
*/
|
||||
public function showMembers(
|
||||
Request $request,
|
||||
Auth $auth
|
||||
): Response {
|
||||
$result = $auth->status();
|
||||
if ($result["status"]) {
|
||||
/*
|
||||
return $render->renderPage(
|
||||
["bgImage" => "", "mode" => "index"],
|
||||
"The Nile List | Members",
|
||||
"dash/members.html.twig"
|
||||
);
|
||||
*/
|
||||
} else {
|
||||
//back to index to login
|
||||
header("Location:/knockknock");
|
||||
return new Response("<html><body>LOGGED IN</body></html>");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/screendoor/members/add", name="members-add")
|
||||
*/
|
||||
public function addMembers(
|
||||
Request $request,
|
||||
Auth $auth,
|
||||
HandleMembers $members,
|
||||
ManagerRegistry $doctrine
|
||||
): 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"
|
||||
]);
|
||||
} else {
|
||||
//add new member
|
||||
$token = $request->get("token");
|
||||
$notice = "";
|
||||
$entityManager = $doctrine->getManager();
|
||||
|
||||
//token check
|
||||
if (!$this->isCsrfTokenValid("upload", $token)) {
|
||||
$logger->info("CSRF failure");
|
||||
|
||||
return new Response(
|
||||
"Operation not allowed",
|
||||
Response::HTTP_BAD_REQUEST,
|
||||
[
|
||||
"content-type" => "text/plain",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
$request->request->get("handle") == "" ||
|
||||
$request->request->get("role") == "" ||
|
||||
$request->request->get("gender") == "" ||
|
||||
$request->request->get("email") == "" ||
|
||||
$request->request->get("pronoun") == ""
|
||||
) {
|
||||
return new Response("<html><body>All fields required</body></html>");
|
||||
|
||||
/*
|
||||
$notice = "All fields are required, champ.";
|
||||
return $render->renderPage(
|
||||
["bgImage" => "", "mode" => "add", "notice" => $notice],
|
||||
"The Nile List | Add Member Error",
|
||||
"dash/members.html.twig"
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
if (
|
||||
!filter_var($request->request->get("email"), FILTER_VALIDATE_EMAIL)
|
||||
) {
|
||||
return new Response("<html><body>BOGUS EMAIL</body></html>");
|
||||
|
||||
/*
|
||||
$notice = "Need a valid email, slick.";
|
||||
return $render->renderPage(
|
||||
["bgImage" => "", "mode" => "add", "notice" => $notice],
|
||||
"The Nile List | Add Member Error",
|
||||
"dash/members.html.twig"
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
//check clear, call add method
|
||||
$response = $members->addMember($request);
|
||||
if ($response["status"]) {
|
||||
/*
|
||||
return $render->renderPage(
|
||||
[
|
||||
"bgImage" => "",
|
||||
"mode" => "add",
|
||||
"notice" => $response["message"],
|
||||
],
|
||||
"The Nile List | Add Members",
|
||||
"dash/members.html.twig"
|
||||
);
|
||||
*/
|
||||
return new Response("<html><body>MEMBER ADDED</body></html>");
|
||||
} else {
|
||||
return new Response("<html><body>" . $response["message"] . "</body></html>");
|
||||
/*
|
||||
return $render->renderPage(
|
||||
["bgImage" => "", "message" => $response["message"]],
|
||||
"The Nile List | Uh Oh Time",
|
||||
"front/error.html.twig"
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//back to index to login
|
||||
header("Location:/knockknock");
|
||||
return new Response("<html><body>LOGGED IN</body></html>");
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,6 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
|
||||
//use App\Utils\PageRender;
|
||||
//use App\Data\Auth;
|
||||
@ -22,7 +21,7 @@ class Index extends AbstractController
|
||||
public function showIndex(Request $request): Response
|
||||
{
|
||||
return $this->render("front/index.twig", [
|
||||
"title" => "This is The Bad Space",
|
||||
"title" => "This is The Bad Space",
|
||||
]);
|
||||
/*
|
||||
$result = $auth->status();
|
||||
@ -42,4 +41,14 @@ class Index extends AbstractController
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/knockknock", name="access")
|
||||
*/
|
||||
public function access(Request $request): Response
|
||||
{
|
||||
return $this->render("front/knock.twig", [
|
||||
"title" => "Wipe Your feet",
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user