-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add security, fixtures and admin backend
- Loading branch information
Showing
14 changed files
with
578 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.php_cs.cache | ||
docker-compose.override.yaml | ||
|
||
###> symfony/framework-bundle ### | ||
/.env.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
#easy_admin: | ||
# entities: | ||
# # List the entity class name you want to manage | ||
# - App\Entity\Product | ||
# - App\Entity\Category | ||
# - App\Entity\User | ||
easy_admin: | ||
entities: | ||
- App\Entity\Helper | ||
- App\Entity\HelpRequest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
security: | ||
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers | ||
encoders: | ||
App\Entity\Admin: | ||
algorithm: auto | ||
|
||
providers: | ||
users_in_memory: { memory: null } | ||
app_user_provider: | ||
entity: | ||
class: App\Entity\Admin | ||
property: username | ||
firewalls: | ||
dev: | ||
pattern: ^/(_(profiler|wdt)|css|images|js)/ | ||
security: false | ||
|
||
main: | ||
anonymous: lazy | ||
provider: users_in_memory | ||
|
||
# activate different ways to authenticate | ||
# https://symfony.com/doc/current/security.html#firewalls-authentication | ||
|
||
# https://symfony.com/doc/current/security/impersonating_user.html | ||
# switch_user: true | ||
provider: app_user_provider | ||
guard: | ||
authenticators: | ||
- App\Security\AdminAuthenticator | ||
logout: | ||
path: app_logout | ||
target: homepage | ||
|
||
# Easy way to control access for large sections of your site | ||
# Note: Only the *first* access control that matches will be used | ||
access_control: | ||
# - { path: ^/admin, roles: ROLE_ADMIN } | ||
# - { path: ^/profile, roles: ROLE_USER } | ||
- { path: ^/admin, roles: ROLE_ADMIN } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: '3' | ||
|
||
services: | ||
database: | ||
ports: | ||
- "5432:5432" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; | ||
|
||
class SecurityController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/login", name="security_login") | ||
*/ | ||
public function login(AuthenticationUtils $authenticationUtils): Response | ||
{ | ||
if ($this->getUser()) { | ||
return $this->redirectToRoute('easyadmin'); | ||
} | ||
|
||
$error = $authenticationUtils->getLastAuthenticationError(); | ||
$lastUsername = $authenticationUtils->getLastUsername(); | ||
|
||
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]); | ||
} | ||
|
||
/** | ||
* @Route("/logout", name="security_logout") | ||
*/ | ||
public function logout() | ||
{ | ||
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="App\Repository\AdminRepository") | ||
* @ORM\Table(name="admins") | ||
*/ | ||
class Admin implements UserInterface | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="bigint", options={"unsigned": true}) | ||
*/ | ||
private ?int $id; | ||
|
||
/** | ||
* @ORM\Column(length=180, unique=true) | ||
*/ | ||
public ?string $username; | ||
|
||
/** | ||
* @var string The hashed password | ||
* | ||
* @ORM\Column() | ||
*/ | ||
private ?string $password; | ||
|
||
public function __toString() | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* A visual identifier that represents this user. | ||
* | ||
* @see UserInterface | ||
*/ | ||
public function getUsername(): string | ||
{ | ||
return (string) $this->username; | ||
} | ||
|
||
/** | ||
* @see UserInterface | ||
*/ | ||
public function getRoles(): array | ||
{ | ||
return ['ROLE_USER', 'ROLE_ADMIN']; | ||
} | ||
|
||
/** | ||
* @see UserInterface | ||
*/ | ||
public function getPassword(): string | ||
{ | ||
return (string) $this->password; | ||
} | ||
|
||
public function setPassword(string $password) | ||
{ | ||
$this->password = $password; | ||
} | ||
|
||
/** | ||
* @see UserInterface | ||
*/ | ||
public function getSalt() | ||
{ | ||
} | ||
|
||
/** | ||
* @see UserInterface | ||
*/ | ||
public function eraseCredentials() | ||
{ | ||
} | ||
} |
Oops, something went wrong.