Skip to content

Commit

Permalink
Use attributes instead of annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan authored and scheb committed Jan 21, 2023
1 parent 96ea9bc commit 129f90a
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 50 deletions.
3 changes: 1 addition & 2 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"ext-json": "*",
"doctrine/annotations": "^1.13",
"doctrine/doctrine-bundle": "^2.0.3",
"doctrine/orm": "^2.0",
"doctrine/orm": "^2.9",
"egulias/email-validator": "^3.0",
"endroid/qr-code": "^4.0",
"lcobucci/clock": "^2.0 || ^3.0",
Expand Down
2 changes: 1 addition & 1 deletion app/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ doctrine:
mappings:
App:
is_bundle: false
type: annotation
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
4 changes: 1 addition & 3 deletions app/src/Controller/EsiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class EsiController extends AbstractController
{
/**
* @Route("/esi/navigation", name="navigation")
*/
#[Route('/esi/navigation', name: 'navigation')]
public function navigation(): Response
{
return $this->render('_navigation.html.twig');
Expand Down
8 changes: 2 additions & 6 deletions app/src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@

class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
*/
#[Route('/', name: 'home')]
public function home(): Response
{
return $this->render('home.html.twig');
}

/**
* @Route("/alwaysAccessible", name="always_accessible")
*/
#[Route('/alwaysAccessible', name: 'always_accessible')]
public function alwaysAccessible(): Response
{
return new Response('This page is accessible for any user any time');
Expand Down
4 changes: 1 addition & 3 deletions app/src/Controller/MembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

class MembersController extends AbstractController
{
/**
* @Route("/members", name="members_area")
*/
#[Route('/members', name: 'members_area')]
public function membersArea(TokenStorageInterface $tokenStorage): Response
{
$user = $tokenStorage->getToken()->getUser();
Expand Down
8 changes: 2 additions & 6 deletions app/src/Controller/QrCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

class QrCodeController extends AbstractController
{
/**
* @Route("/members/qr/ga", name="qr_code_ga")
*/
#[Route('/members/qr/ga', name: 'qr_code_ga')]
public function displayGoogleAuthenticatorQrCode(TokenStorageInterface $tokenStorage, GoogleAuthenticatorInterface $googleAuthenticator): Response
{
$user = $tokenStorage->getToken()->getUser();
Expand All @@ -34,9 +32,7 @@ public function displayGoogleAuthenticatorQrCode(TokenStorageInterface $tokenSto
return $this->displayQrCode($googleAuthenticator->getQRContent($user));
}

/**
* @Route("/members/qr/totp", name="qr_code_totp")
*/
#[Route('/members/qr/totp', name: 'qr_code_totp')]
public function displayTotpQrCode(TokenStorageInterface $tokenStorage, TotpAuthenticatorInterface $totpAuthenticator): Response
{
$user = $tokenStorage->getToken()->getUser();
Expand Down
12 changes: 3 additions & 9 deletions app/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

class SecurityController extends AbstractController
{
/**
* @Route("/login", name="_security_login")
*/
#[Route('/login', name: '_security_login')]
public function login(AuthenticationUtils $authUtils): Response
{
// get the login error if there is one
Expand All @@ -30,9 +28,7 @@ public function login(AuthenticationUtils $authUtils): Response
]);
}

/**
* @Route("/password", name="_security_password")
*/
#[Route('/password', name: '_security_password')]
public function register(UserPasswordHasherInterface $hasher): Response
{
$user = new User();
Expand All @@ -42,9 +38,7 @@ public function register(UserPasswordHasherInterface $hasher): Response
return new Response($encoded);
}

/**
* @Route("/2fa/inProgress", name="2fa_in_progress")
*/
#[Route('/2fa/inProgress', name: '2fa_in_progress')]
public function accessibleDuring2fa(): Response
{
return new Response('This page is accessible during 2fa');
Expand Down
34 changes: 15 additions & 19 deletions app/src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,40 @@
use Symfony\Component\Security\Core\User\UserInterface;
use function in_array;

/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
#[ORM\Entity]
#[ORM\Table(name: 'user')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, EmailTwoFactorInterface, GoogleTwoFactorInterface, TotpTwoFactorInterface, TrustedDeviceInterface, BackupCodeInterface
{
private const BACKUP_CODES = [111, 222];
public const TRUSTED_TOKEN_VERSION = 1;

/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private int $id;

/** @ORM\Column(type="string", length=25, unique=true) */
#[ORM\Column(type: 'string', length: 25, unique: true)]
private string $username;

/** @ORM\Column(type="string", length=64) */
#[ORM\Column(type: 'string', length: 64)]
private string $password;

/** @ORM\Column(type="string", length=60, unique=true) */
#[ORM\Column(type: 'string', length: 60, unique: true)]
private string $email;

/** @ORM\Column(type="boolean") */
#[ORM\Column(type: 'boolean')]
private bool $emailAuthenticationEnabled = true;

/** @ORM\Column(type="integer") */
private ?string $emailAuthenticationCode;
#[ORM\Column(type: 'integer')]
private ?string $emailAuthenticationCode = null;

/** @ORM\Column(type="boolean") */
#[ORM\Column(type: 'boolean')]
private bool $googleAuthenticatorEnabled = true;

/** @ORM\Column(type="string") */
private ?string $googleAuthenticatorSecret;
#[ORM\Column(type: 'string')]
private ?string $googleAuthenticatorSecret = null;

/** @ORM\Column(type="boolean") */
#[ORM\Column(type: 'boolean')]
private bool $totpAuthenticationEnabled = true;

public function getId(): int
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"symfony/twig-bundle": "^5.4 || ^6.0"
},
"require-dev": {
"doctrine/annotations": "^1.13 || ^2.0",
"doctrine/coding-standard": "^9.0",
"doctrine/persistence": "^1.3 || ^2.0",
"egulias/email-validator": "^3.0",
Expand Down

0 comments on commit 129f90a

Please sign in to comment.