diff --git a/.idea/spt-crm-backend.iml b/.idea/spt-crm-backend.iml index c956989..624d9cb 100644 --- a/.idea/spt-crm-backend.iml +++ b/.idea/spt-crm-backend.iml @@ -1,7 +1,88 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/httpdocs/composer.json b/httpdocs/composer.json index 7995373..5d9aca5 100644 --- a/httpdocs/composer.json +++ b/httpdocs/composer.json @@ -70,5 +70,8 @@ "allow-contrib": false, "require": "6.2.*" } + }, + "require-dev": { + "symfony/debug-bundle": "6.2.*" } } diff --git a/httpdocs/composer.lock b/httpdocs/composer.lock index 8e87fcf..47c3c6a 100644 --- a/httpdocs/composer.lock +++ b/httpdocs/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9de26d479d080ba6069e18310ae49ab9", + "content-hash": "15a7bf65293c8d623f82986b5c017838", "packages": [ { "name": "doctrine/annotations", @@ -5813,7 +5813,359 @@ "time": "2023-04-28T13:25:36+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "symfony/debug-bundle", + "version": "v6.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug-bundle.git", + "reference": "8ff6c96d09c462beade7512137899e400c76d994" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug-bundle/zipball/8ff6c96d09c462beade7512137899e400c76d994", + "reference": "8ff6c96d09c462beade7512137899e400c76d994", + "shasum": "" + }, + "require": { + "ext-xml": "*", + "php": ">=8.1", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/twig-bridge": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0" + }, + "conflict": { + "symfony/config": "<5.4", + "symfony/dependency-injection": "<5.4" + }, + "require-dev": { + "symfony/config": "^5.4|^6.0", + "symfony/web-profiler-bundle": "^5.4|^6.0" + }, + "suggest": { + "symfony/config": "For service container configuration", + "symfony/dependency-injection": "For using as a service from the container" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Symfony\\Bundle\\DebugBundle\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/debug-bundle/tree/v6.2.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-02-14T08:44:56+00:00" + }, + { + "name": "symfony/translation-contracts", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation-contracts.git", + "reference": "02c24deb352fb0d79db5486c0c79905a85e37e86" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/02c24deb352fb0d79db5486c0c79905a85e37e86", + "reference": "02c24deb352fb0d79db5486c0c79905a85e37e86", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Test/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to translation", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "support": { + "source": "https://github.com/symfony/translation-contracts/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-30T17:17:10+00:00" + }, + { + "name": "symfony/twig-bridge", + "version": "v6.2.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/twig-bridge.git", + "reference": "30e3ad6ae749b2d2700ecf9b4a1a9d5c96b18927" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/twig-bridge/zipball/30e3ad6ae749b2d2700ecf9b4a1a9d5c96b18927", + "reference": "30e3ad6ae749b2d2700ecf9b4a1a9d5c96b18927", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/translation-contracts": "^1.1|^2|^3", + "twig/twig": "^2.13|^3.0.4" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/console": "<5.4", + "symfony/form": "<6.2.7", + "symfony/http-foundation": "<5.4", + "symfony/http-kernel": "<6.2", + "symfony/mime": "<6.2", + "symfony/translation": "<5.4", + "symfony/workflow": "<5.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12|^2", + "egulias/email-validator": "^2.1.10|^3|^4", + "league/html-to-markdown": "^5.0", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/asset": "^5.4|^6.0", + "symfony/console": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/expression-language": "^5.4|^6.0", + "symfony/finder": "^5.4|^6.0", + "symfony/form": "^6.2.7", + "symfony/html-sanitizer": "^6.1", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/http-kernel": "^6.2", + "symfony/intl": "^5.4|^6.0", + "symfony/mime": "^6.2", + "symfony/polyfill-intl-icu": "~1.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/routing": "^5.4|^6.0", + "symfony/security-acl": "^2.8|^3.0", + "symfony/security-core": "^5.4|^6.0", + "symfony/security-csrf": "^5.4|^6.0", + "symfony/security-http": "^5.4|^6.0", + "symfony/serializer": "^6.2", + "symfony/stopwatch": "^5.4|^6.0", + "symfony/translation": "^5.4|^6.0", + "symfony/web-link": "^5.4|^6.0", + "symfony/workflow": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0", + "twig/cssinliner-extra": "^2.12|^3", + "twig/inky-extra": "^2.12|^3", + "twig/markdown-extra": "^2.12|^3" + }, + "suggest": { + "symfony/asset": "For using the AssetExtension", + "symfony/expression-language": "For using the ExpressionExtension", + "symfony/finder": "", + "symfony/form": "For using the FormExtension", + "symfony/html-sanitizer": "For using the HtmlSanitizerExtension", + "symfony/http-kernel": "For using the HttpKernelExtension", + "symfony/routing": "For using the RoutingExtension", + "symfony/security-core": "For using the SecurityExtension", + "symfony/security-csrf": "For using the CsrfExtension", + "symfony/security-http": "For using the LogoutUrlExtension", + "symfony/stopwatch": "For using the StopwatchExtension", + "symfony/translation": "For using the TranslationExtension", + "symfony/var-dumper": "For using the DumpExtension", + "symfony/web-link": "For using the WebLinkExtension", + "symfony/yaml": "For using the YamlExtension" + }, + "type": "symfony-bridge", + "autoload": { + "psr-4": { + "Symfony\\Bridge\\Twig\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides integration for Twig with various Symfony components", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/twig-bridge/tree/v6.2.8" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-03-31T09:14:44+00:00" + }, + { + "name": "twig/twig", + "version": "v3.6.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/Twig.git", + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/106c170d08e8415d78be2d16c3d057d0d108262b", + "reference": "106c170d08e8415d78be2d16c3d057d0d108262b", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-mbstring": "^1.3" + }, + "require-dev": { + "psr/container": "^1.0|^2.0", + "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Twig\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Twig Team", + "role": "Contributors" + }, + { + "name": "Armin Ronacher", + "email": "armin.ronacher@active-4.com", + "role": "Project Founder" + } + ], + "description": "Twig, the flexible, fast, and secure template language for PHP", + "homepage": "https://twig.symfony.com", + "keywords": [ + "templating" + ], + "support": { + "issues": "https://github.com/twigphp/Twig/issues", + "source": "https://github.com/twigphp/Twig/tree/v3.6.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2023-05-03T19:06:57+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/httpdocs/config/bundles.php b/httpdocs/config/bundles.php index c2cb463..49cc044 100644 --- a/httpdocs/config/bundles.php +++ b/httpdocs/config/bundles.php @@ -6,4 +6,5 @@ return [ Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], + Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], ]; diff --git a/httpdocs/config/packages/debug.yaml b/httpdocs/config/packages/debug.yaml new file mode 100644 index 0000000..ad874af --- /dev/null +++ b/httpdocs/config/packages/debug.yaml @@ -0,0 +1,5 @@ +when@dev: + debug: + # Forwards VarDumper Data clones to a centralized server allowing to inspect dumps on CLI or in your browser. + # See the "server:dump" command to start a new server. + dump_destination: "tcp://%env(VAR_DUMPER_SERVER)%" diff --git a/httpdocs/config/packages/doctrine.yaml b/httpdocs/config/packages/doctrine.yaml index b284b6d..a3eadf3 100644 --- a/httpdocs/config/packages/doctrine.yaml +++ b/httpdocs/config/packages/doctrine.yaml @@ -18,6 +18,7 @@ doctrine: dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App + type: attribute when@test: doctrine: diff --git a/httpdocs/config/packages/security.yaml b/httpdocs/config/packages/security.yaml index 367af25..f07ebaa 100644 --- a/httpdocs/config/packages/security.yaml +++ b/httpdocs/config/packages/security.yaml @@ -5,6 +5,9 @@ security: # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider providers: users_in_memory: { memory: null } + app_entity_users: + entity: + class: App\Entity\EntUser firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ @@ -12,6 +15,8 @@ security: main: lazy: true provider: users_in_memory + custom_authenticators: + - App\Security\JsonAuthenticator # activate different ways to authenticate # https://symfony.com/doc/current/security.html#the-firewall diff --git a/httpdocs/src/Controller/PublicController.php b/httpdocs/src/Controller/PublicController.php index 702c0ae..b443930 100644 --- a/httpdocs/src/Controller/PublicController.php +++ b/httpdocs/src/Controller/PublicController.php @@ -12,6 +12,7 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; class PublicController extends AbstractController { @@ -37,9 +38,10 @@ class PublicController extends AbstractController } #[Route('/login', name: 'login')] - public function loginAction() + public function loginAction(AuthenticationUtils $authenticationUtils) { - $error = $this->get('security.authentication_utils')->getLastAuthenticationError(); + // get the login error if there is one + $error = $authenticationUtils->getLastAuthenticationError(); $data = [ 'error' => $error diff --git a/httpdocs/src/Entity/EntCountry.php b/httpdocs/src/Entity/EntCountry.php index a45e08f..7c079ed 100644 --- a/httpdocs/src/Entity/EntCountry.php +++ b/httpdocs/src/Entity/EntCountry.php @@ -8,10 +8,8 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="country") - */ +#[ORM\Table(name: 'country')] +#[ORM\Entity] class EntCountry implements IEntity { const COUNTRY_GERMANY_ID = 1; @@ -29,21 +27,15 @@ class EntCountry implements IEntity self::COUNTRY_FRANCE_ID => 'Frankreich', ); - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="string", length=50, nullable=false) - */ + #[ORM\Column(type: 'string', length: 50, nullable: false)] protected $name; - /** - * @ORM\Column(type="string", length=3) - */ + #[ORM\Column(type: 'string', length: 3)] protected $iso_code; diff --git a/httpdocs/src/Entity/EntCustomer.php b/httpdocs/src/Entity/EntCustomer.php index 15fc042..666295a 100644 --- a/httpdocs/src/Entity/EntCustomer.php +++ b/httpdocs/src/Entity/EntCustomer.php @@ -8,102 +8,64 @@ use App\Utils\Utils; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="customer") - */ +#[ORM\Table(name: 'customer')] +#[ORM\Entity] class EntCustomer implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $old_plp_id; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $name; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $name_additional; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $consultant_user_id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $zip; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $city; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $country_id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $url; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $email; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $phone_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $mobile_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $fax_no; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $comment; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $active; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; /** diff --git a/httpdocs/src/Entity/EntCustomerContact.php b/httpdocs/src/Entity/EntCustomerContact.php index 2762d7f..7382e5c 100644 --- a/httpdocs/src/Entity/EntCustomerContact.php +++ b/httpdocs/src/Entity/EntCustomerContact.php @@ -10,107 +10,67 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="customer_contact") - */ +#[ORM\Table(name: 'customer_contact')] +#[ORM\Entity] class EntCustomerContact implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $customer_id; - /** - * @ORM\Column(name="gender", type="string", columnDefinition="ENUM('male', 'female', 'diverse')") - */ + #[ORM\Column(name: 'gender', type: 'string', columnDefinition: "ENUM('male', 'female', 'diverse')")] protected $gender; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $firstname; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $lastname; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $email; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $phone_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $mobile_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $fax_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $department; - /** - * @ORM\Column(type="date", nullable=true) - */ + #[ORM\Column(type: 'date', nullable: true)] protected $date_of_birth; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $zip; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $city; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $country_id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $comment; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $is_xmas_mail_recipient = false; /** diff --git a/httpdocs/src/Entity/EntCustomerMeeting.php b/httpdocs/src/Entity/EntCustomerMeeting.php index ecc348b..a6c5b4d 100644 --- a/httpdocs/src/Entity/EntCustomerMeeting.php +++ b/httpdocs/src/Entity/EntCustomerMeeting.php @@ -9,157 +9,98 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="customer_meeting", indexes={@ORM\Index(name="search_customer_idx", columns={"customer_id", "owner_user_id", "customer_contact_id"})}) - */ +#[ORM\Table(name: 'customer_meeting')] +#[ORM\Index(name: 'search_customer_idx', columns: ['customer_id', 'owner_user_id', 'customer_contact_id'])] +#[ORM\Entity] class EntCustomerMeeting implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $customer_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $creation_user_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $owner_user_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $meeting_type_id; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $is_option_meeting; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $title; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $description; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $start_date; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $end_date; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $customer_contact_id; - /** - * @ORM\Column(name="gender", type="string", columnDefinition="enum('male', 'female', 'diverse')") - */ + #[ORM\Column(name: 'gender', type: 'string', columnDefinition: "enum('male', 'female', 'diverse')")] protected $gender; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $firstname; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $lastname; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $email; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $phone_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $mobile_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $department; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $street_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $zip; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $city; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $country_id; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $report; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $first_reminder_sent; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $second_reminder_sent; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $report_done; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $report_reminder_sent; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; diff --git a/httpdocs/src/Entity/EntCustomerMeetingParticipant.php b/httpdocs/src/Entity/EntCustomerMeetingParticipant.php index e26ccce..049d36c 100644 --- a/httpdocs/src/Entity/EntCustomerMeetingParticipant.php +++ b/httpdocs/src/Entity/EntCustomerMeetingParticipant.php @@ -9,28 +9,21 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\UniqueConstraint; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="customer_meeting_participant",indexes={@ORM\Index(name="search_participant_idx", columns={"customer_meeting_id", "participant_user_id"})}, - * uniqueConstraints={@UniqueConstraint(name="unique_participant", columns={"customer_meeting_id", "participant_user_id"})}) - */ +#[ORM\Table(name: 'customer_meeting_participant')] +#[ORM\Index(name: 'search_participant_idx', columns: ['customer_meeting_id', 'participant_user_id'])] +#[UniqueConstraint(name: 'unique_participant', columns: ['customer_meeting_id', 'participant_user_id'])] +#[ORM\Entity] class EntCustomerMeetingParticipant implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $customer_meeting_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $participant_user_id; diff --git a/httpdocs/src/Entity/EntCustomerNote.php b/httpdocs/src/Entity/EntCustomerNote.php index 490d1fb..e37be01 100644 --- a/httpdocs/src/Entity/EntCustomerNote.php +++ b/httpdocs/src/Entity/EntCustomerNote.php @@ -9,102 +9,64 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="customer_note") - */ +#[ORM\Table(name: 'customer_note')] +#[ORM\Entity] class EntCustomerNote implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $customer_id; - /** - * @ORM\Column(type="integer", nullable=true, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])] protected $customer_contact_id; - /** - * @ORM\Column(name="gender", type="string", columnDefinition="enum('male', 'female', 'diverse')") - */ + #[ORM\Column(name: 'gender', type: 'string', columnDefinition: "enum('male', 'female', 'diverse')")] protected $gender; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $firstname; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $lastname; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $email; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $phone_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $mobile_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $fax_no; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $department; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $title; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $comment; - /** - * @ORM\Column(type="date", nullable=false) - */ + #[ORM\Column(type: 'date', nullable: false)] protected $note_date; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $creation_user_id; - /** - * @ORM\Column(type="string", nullable=true) - */ + #[ORM\Column(type: 'string', nullable: true)] protected $creation_user_firstname; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $creation_user_lastname; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; diff --git a/httpdocs/src/Entity/EntInternalMeeting.php b/httpdocs/src/Entity/EntInternalMeeting.php index e635f6a..6bd15b5 100644 --- a/httpdocs/src/Entity/EntInternalMeeting.php +++ b/httpdocs/src/Entity/EntInternalMeeting.php @@ -9,72 +9,47 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="internal_meeting", indexes={@ORM\Index(name="search_owner_idx", columns={"owner_user_id"})}) - */ +#[ORM\Table(name: 'internal_meeting')] +#[ORM\Index(name: 'search_owner_idx', columns: ['owner_user_id'])] +#[ORM\Entity] class EntInternalMeeting implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $creation_user_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $owner_user_id; - /** - * @ORM\Column(type="string", nullable=false) - */ + #[ORM\Column(type: 'string', nullable: false)] protected $title; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $description; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $start_date; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $end_date; - /** - * @ORM\Column(type="text", nullable=true) - */ + #[ORM\Column(type: 'text', nullable: true)] protected $report; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $first_reminder_sent; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $second_reminder_sent; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected $report_reminder_sent; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; diff --git a/httpdocs/src/Entity/EntInternalMeetingParticipant.php b/httpdocs/src/Entity/EntInternalMeetingParticipant.php index 7092420..86b802b 100644 --- a/httpdocs/src/Entity/EntInternalMeetingParticipant.php +++ b/httpdocs/src/Entity/EntInternalMeetingParticipant.php @@ -9,28 +9,21 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\UniqueConstraint; use Symfony\Component\Config\Definition\Exception\Exception; -/** - * @ORM\Entity - * @ORM\Table(name="internal_meeting_participant",indexes={@ORM\Index(name="search_participant_idx", columns={"internal_meeting_id", "participant_user_id"})}, - * uniqueConstraints={@UniqueConstraint(name="unique_participant", columns={"internal_meeting_id", "participant_user_id"})}) - */ +#[ORM\Table(name: 'internal_meeting_participant')] +#[ORM\Index(name: 'search_participant_idx', columns: ['internal_meeting_id', 'participant_user_id'])] +#[UniqueConstraint(name: 'unique_participant', columns: ['internal_meeting_id', 'participant_user_id'])] +#[ORM\Entity] class EntInternalMeetingParticipant implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $internal_meeting_id; - /** - * @ORM\Column(type="integer", nullable=false, options={"unsigned" = true}) - */ + #[ORM\Column(type: 'integer', nullable: false, options: ['unsigned' => true])] protected $participant_user_id; diff --git a/httpdocs/src/Entity/EntMeetingType.php b/httpdocs/src/Entity/EntMeetingType.php index 50cc128..d18992a 100644 --- a/httpdocs/src/Entity/EntMeetingType.php +++ b/httpdocs/src/Entity/EntMeetingType.php @@ -7,27 +7,19 @@ use App\Utils\Utils; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="meeting_type") - */ +#[ORM\Table(name: 'meeting_type')] +#[ORM\Entity] class EntMeetingType implements IEntity { - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(type="string", nullable=false, unique=true) - */ + #[ORM\Column(type: 'string', nullable: false, unique: true)] protected $type; - /** - * @ORM\Column(type="string", nullable=false, unique=true) - */ + #[ORM\Column(type: 'string', nullable: false, unique: true)] protected $name; private static $cacheMeetingTypesById; diff --git a/httpdocs/src/Entity/EntUser.php b/httpdocs/src/Entity/EntUser.php index 8173e11..d90e818 100644 --- a/httpdocs/src/Entity/EntUser.php +++ b/httpdocs/src/Entity/EntUser.php @@ -9,56 +9,43 @@ use Doctrine\DBAL\Types\Types; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Config\Definition\Exception\Exception; +use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\UserInterface; -#[ORM\Entity()] -class EntUser implements IEntity, UserInterface +#[ORM\Entity] +#[ORM\Table(name: "user")] +class EntUser implements IEntity, UserInterface, PasswordAuthenticatedUserInterface { - // User id of system - const SYSTEM_USER_ID = 0; - // Costs of password encryption const CRYPT_COST = 12; #[ORM\Id] - #[ORM\GeneratedValue] - #[ORM\Column] + #[ORM\Column(type: "integer")] + #[ORM\GeneratedValue(strategy: "AUTO")] protected int $id; - #[ORM\Column(Types::STRING, unique: true)] + #[ORM\Column(type: Types::STRING, unique: true)] protected string $email; - #[ORM\Column(Types::INTEGER)] - protected int $user_type_id; + #[ORM\Column(type: 'json')] + private array $roles = []; - /** - * @ORM\Column(type="string", length=50, nullable=false) - */ + #[ORM\Column(type: 'string', length: 50, nullable: false)] protected string $firstname; - /** - * @ORM\Column(type="string", length=50, nullable=false) - */ + #[ORM\Column(type: 'string', length: 50, nullable: false)] protected string $lastname; - /** - * @ORM\Column(type="string", length=60, nullable=false) - */ + #[ORM\Column(type: 'string', length: 60, nullable: false)] protected string $password; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected bool $active; - /** - * @ORM\Column(type="boolean", nullable=false) - */ + #[ORM\Column(type: 'boolean', nullable: false)] protected bool $visible; - /** - * @ORM\Column(type="datetime", nullable=false) - */ + #[ORM\Column(type: 'datetime', nullable: false)] protected $creation_date; /** @@ -68,19 +55,17 @@ class EntUser implements IEntity, UserInterface * @param $firstName * @param $lastName * @param $password - * @param $userTypeId * @param $userTypeIdCreatingUser * @param EntUser|null $editingUser * @throws \Exception */ - public function __construct(EntityManagerInterface $em, $email, $firstName, $lastName, $password, $userTypeId, $userTypeIdCreatingUser, EntUser $editingUser = null) + public function __construct(EntityManagerInterface $em, $email, $firstName, $lastName, $password, $userTypeIdCreatingUser, EntUser $editingUser = null) { // Check email if (!Utils::validateEmail($em, $email)) { throw new Exception('invalid or existent email given: '.$email); } - $this->setUserTypeId($userTypeIdCreatingUser, $userTypeId, $editingUser); // Check password length if (!Utils::isValidPasswordLength($password)) { @@ -88,7 +73,6 @@ class EntUser implements IEntity, UserInterface } $this->email = $email; - $this->user_type_id = $userTypeId; $this->firstname = $firstName; $this->lastname = $lastName; $this->password = password_hash($password, PASSWORD_BCRYPT, ["cost" => self::CRYPT_COST]); @@ -108,7 +92,7 @@ class EntUser implements IEntity, UserInterface /** * @return mixed */ - public function getEmail() + public function getEmail(): string { return $this->email; } @@ -116,15 +100,7 @@ class EntUser implements IEntity, UserInterface /** * @return mixed */ - public function getUserTypeId() - { - return $this->user_type_id; - } - - /** - * @return mixed - */ - public function getFirstname() + public function getFirstname(): string { return $this->firstname; } @@ -132,7 +108,7 @@ class EntUser implements IEntity, UserInterface /** * @return mixed */ - public function getLastname() + public function getLastname(): string { return $this->lastname; } @@ -140,7 +116,7 @@ class EntUser implements IEntity, UserInterface /** * @return mixed */ - public function getPassword() + public function getPassword(): ?string { return $this->password; } @@ -164,7 +140,7 @@ class EntUser implements IEntity, UserInterface /** * @return mixed */ - public function getCreationDate() + public function getCreationDate(): string { return $this->creation_date; } @@ -178,13 +154,20 @@ class EntUser implements IEntity, UserInterface return $this->email; } - /** - * Returns roles as part of UserInterface needed in Symfony - * @return string[] - */ public function getRoles(): array { - return EntUserType::getUserRoles($this->user_type_id); + $roles = $this->roles; + // guarantee every user at least has ROLE_USER + $roles[] = 'ROLE_USER'; + + return array_unique($roles); + } + + public function setRoles(array $roles): self + { + $this->roles = $roles; + + return $this; } /** @@ -217,27 +200,6 @@ class EntUser implements IEntity, UserInterface */ public function getSalt() {} - /** - * @param $userTypeIdCreatingUser - * @param $userTypeId - * @param EntUser|null $editingUser - */ - public function setUserTypeId($userTypeIdCreatingUser, $userTypeId, EntUser $editingUser = null): void - { - // Check user type id - if (!EntUserType::isValidUserTypeId($userTypeId)) { - throw new Exception('invalid user type id'); - } - - // Compare creating user type with this user type - $isEditingUser = is_null($editingUser) ? false : $editingUser->getId() == $this->id; - if (!EntUserType::isHigherUserType($userTypeIdCreatingUser, $userTypeId) && !$isEditingUser) { - throw new Exception('creating user has not enough rights to create this user type'); - } - $this->user_type_id = $userTypeId; - - } - /** * Sets email with check on validity and existence * @param ObjectManager $em @@ -327,9 +289,6 @@ class EntUser implements IEntity, UserInterface */ public function clientMapper(EntityManagerInterface $em, $fullMapping = false) { - /** @var EntUserType $userType */ - $userType = $em->getRepository('App:EntUserType')->find($this->user_type_id); - return [ 'id' => $this->id, 'email' => $this->email, @@ -337,8 +296,6 @@ class EntUser implements IEntity, UserInterface 'lastname' => $this->lastname, 'active' => $this->active, 'visible' => $this->visible, - 'v_translated_role' => EntUserType::getTranslatedRole($this->user_type_id), - 'v_user_type' => $userType->clientMapper($em, $fullMapping), ]; } diff --git a/httpdocs/src/Entity/EntUserType.php b/httpdocs/src/Entity/EntUserType.php index dc887eb..c044d41 100644 --- a/httpdocs/src/Entity/EntUserType.php +++ b/httpdocs/src/Entity/EntUserType.php @@ -7,10 +7,8 @@ use Symfony\Component\Config\Definition\Exception\Exception; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - * @ORM\Table(name="user_type") - */ +#[ORM\Table(name: 'user_type')] +#[ORM\Entity] class EntUserType implements IEntity { // User type for system @@ -53,16 +51,12 @@ class EntUserType implements IEntity self::USER_TYPE_ID_SERVICE => 'Service' ); - /** - * @ORM\Id() - * @ORM\GeneratedValue() - * @ORM\Column(type="integer") - */ + #[ORM\Id] + #[ORM\GeneratedValue] + #[ORM\Column(type: 'integer')] protected $id; - /** - * @ORM\Column(name="type", type="string", nullable=false, unique=true) - */ + #[ORM\Column(name: 'type', type: 'string', nullable: false, unique: true)] protected $type; diff --git a/httpdocs/src/Security/JsonAuthenticator.php b/httpdocs/src/Security/JsonAuthenticator.php index 4db3d8a..1335437 100644 --- a/httpdocs/src/Security/JsonAuthenticator.php +++ b/httpdocs/src/Security/JsonAuthenticator.php @@ -10,37 +10,34 @@ namespace App\Security; use App\Entity\EntUser; use App\Utils\Config; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; -use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Security\Core\User\UserProviderInterface; -use Symfony\Component\Security\Guard\AbstractGuardAuthenticator; +use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; +use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; +use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; +use Symfony\Component\Security\Http\Authenticator\Passport\Passport; -class JsonAuthenticator extends AbstractGuardAuthenticator +class JsonAuthenticator extends AbstractAuthenticator { const LOGIN_FAILED = 0; const LOGIN_SUCCESS = 1; private $em; - private $router; - /** @var $user EntUser */ private $user; /** * JsonAuthenticator constructor. - * @param $em + * @param EntityManager $em */ - public function __construct(EntityManager $em, RouterInterface $router) + public function __construct(EntityManagerInterface $em) { $this->em = $em; - $this->router = $router; - $this->user = null; } /** @@ -48,44 +45,26 @@ class JsonAuthenticator extends AbstractGuardAuthenticator * used for the request. Returning false will cause this authenticator * to be skipped. */ - public function supports(Request $request) + public function supports(Request $request): ?bool { - if ($request->getPathInfo() != "/login" || !$request->isMethod('POST')) { - return false; - } - - return !is_null($request->request->get('email')) && - !is_null($request->request->get('password')); - } + if ($request->getPathInfo() === "/login" && $request->isMethod('POST')) { + return !is_null($request->request->get('email')) && !is_null($request->request->get('password')); - /** - * Called on every request. Return whatever credentials you want to - * be passed to getUser() as $credentials. - */ - public function getCredentials(Request $request) - { - return [ - 'email' => $request->request->get('email'), - 'password' => $request->request->get('password'), - ]; - } - - public function getUser($credentials, UserProviderInterface $userProvider) - { - $email = $credentials['email']; - $this->user = $this->em->getRepository('App:EntUser')->findOneBy(['email' => $email]); - - // if a User object, checkCredentials() is called - return $this->user; + } + return false; } - public function checkCredentials($credentials, UserInterface $user) + public function authenticate(Request $request): Passport { - /** @var $user EntUser */ - return !is_null($user) && $user->checkPassword($credentials['password']); + $email = $request->request->get('email'); + $password = $request->request->get('password'); + return new Passport( + new UserBadge($email), + new PasswordCredentials($password) + ); } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) + public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response { // on success, let the request continue $data = array('message' => 'logged in successfully', @@ -96,7 +75,7 @@ class JsonAuthenticator extends AbstractGuardAuthenticator return new JsonResponse($data, Response::HTTP_ACCEPTED); } - public function onAuthenticationFailure(Request $request, AuthenticationException $exception) + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response { $data = array( 'message' => strtr($exception->getMessageKey(), $exception->getMessageData()), diff --git a/httpdocs/src/Utils/Config.php b/httpdocs/src/Utils/Config.php index db06a40..c242914 100644 --- a/httpdocs/src/Utils/Config.php +++ b/httpdocs/src/Utils/Config.php @@ -9,23 +9,16 @@ namespace App\Utils; -use App\Entity\EntCadasterGlassSurfaceEntry; -use App\Entity\EntCadasterLocalizationEntry; -use App\Entity\EntCadasterTreeEntry; -use App\Entity\EntCountry; -use App\Entity\EntLocationObject; -use App\Entity\EntQualityRequirementRoom; -use App\Entity\EntUserType; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityManagerInterface; class Config { /** * Returns api config - * @param ObjectManager $em + * @param EntityManagerInterface $em * @return array */ - public static function getConfig(ObjectManager $em) + public static function getConfig(EntityManagerInterface $em) { return [ 'users' => Utils::clientMap($em, $em->getRepository('App:EntUser')->findBy(['visible' => true])), diff --git a/httpdocs/symfony.lock b/httpdocs/symfony.lock index 3fbc0fc..db565b9 100644 --- a/httpdocs/symfony.lock +++ b/httpdocs/symfony.lock @@ -59,6 +59,18 @@ "bin/console" ] }, + "symfony/debug-bundle": { + "version": "6.2", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "5.3", + "ref": "5aa8aa48234c8eb6dbdd7b3cd5d791485d2cec4b" + }, + "files": [ + "config/packages/debug.yaml" + ] + }, "symfony/flex": { "version": "2.2", "recipe": {