mirror of
https://koodu.h-i.works/projects/thebadspace
synced 2025-05-06 14:41:02 -05:00
Now that full-text searching is set up in the DB, the next step is data population. The adding and editing templates were added as long as routes and base functionality to add single locations. Adding works and editing is almost there but both still need to cleaned up. The basic plumbing will be completed and then the tweaking to account for roles and login status for the sake of security. Part 2 will include clean up and and bulk uploads through the use of CSV files.
105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
|
|
|
// src/Controller/ProductController.php
|
|
|
|
namespace App\Service;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use App\Entity\Member;
|
|
use ReallySimpleJWT\Token;
|
|
|
|
class Auth
|
|
{
|
|
private $session;
|
|
private $entityManager;
|
|
|
|
public function __construct(
|
|
EntityManagerInterface $entityManager,
|
|
RequestStack $requestStack
|
|
) {
|
|
$this->entityManager = $entityManager;
|
|
$this->session = $requestStack->getSession();
|
|
$this->secret = '!$ec7eT$l0w*';
|
|
}
|
|
|
|
public function authCheck($handle, $password)
|
|
{
|
|
$response = [];
|
|
$member = new Member();
|
|
$members = $this->entityManager->getRepository(Member::class);
|
|
$member = $members->findOneBy(["handle" => $handle]);
|
|
if (!$member) {
|
|
$response = ["status" => false, "message" => "Member Not Found"];
|
|
} else {
|
|
if (!password_verify($password, $member->getPassword())) {
|
|
$response = ["status" => false, "message" => "Check that password"];
|
|
} else {
|
|
$this->session->set("member", $member);
|
|
|
|
$secret = $this->secret;
|
|
$expiration = time() + 3600;
|
|
$token = Token::create(
|
|
$member->getId(),
|
|
$secret,
|
|
$expiration,
|
|
"bad_space_admin"
|
|
);
|
|
|
|
$this->session->set("token", $token);
|
|
$response = ["status" => true, "message" => "Welcome Back"];
|
|
}
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function logOut()
|
|
{
|
|
$this->session->set("member", null);
|
|
$this->session->set("token", null);
|
|
}
|
|
|
|
public function APIStatus()
|
|
{
|
|
$response = [];
|
|
$verify = Token::validate($this->session->get("token"), $this->secret);
|
|
|
|
if ($verify) {
|
|
$response = [
|
|
"status" => true,
|
|
"message" => "Token is good",
|
|
"token" => $this->session->get("token"),
|
|
];
|
|
} else {
|
|
$response = ["status" => false, "message" => "Bad Token, champ."];
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function status()
|
|
{
|
|
$response = [];
|
|
//checks to see if member session exists
|
|
if ($this->session->get("member")) {
|
|
//checks if token is still valid
|
|
$verify = Token::validateExpiration($this->session->get("token"), $this->secret);
|
|
if ($verify) {
|
|
$response = [
|
|
"status" => true,
|
|
"role" => $this->session->get("member")->getRole(),
|
|
"id" => $this->session->get("member")->getId(),
|
|
"token" => $this->session->get("token"),
|
|
];
|
|
} else {
|
|
$response = ["status" => false, "role" => null];
|
|
}
|
|
} else {
|
|
$response = ["status" => false, "role" => null];
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|