diff --git a/composer.json b/composer.json index 38afbaf211260ad7684b637278ec0b20d5a31656..9b761912c82c66fc8f6ef20cea8ee83f581e7ac1 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,13 @@ "symfony/form": "5.0.*", "symfony/framework-bundle": "5.0.*", "symfony/orm-pack": "^1.0", + "symfony/security-bundle": "5.0.*", "symfony/twig-bundle": "5.0.*", "symfony/webpack-encore-bundle": "^1.7", "symfony/yaml": "5.0.*" }, "require-dev": { + "symfony/maker-bundle": "^1.14" }, "config": { "preferred-install": { diff --git a/composer.lock b/composer.lock index 2a7b3777564b6a89c8e7a141fe1a768bf2839f76..4208f42f9f317acd5aadbbdd3f594753dd3f88c0 100644 --- a/composer.lock +++ b/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": "7a6a91a0b0f80ad4c0c01b42801dbdbe", + "content-hash": "1914f85e20b1121b8cd946411a258802", "packages": [ { "name": "doctrine/annotations", @@ -3595,6 +3595,340 @@ ], "time": "2019-12-12T13:03:32+00:00" }, + { + "name": "symfony/security-bundle", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/security-bundle.git", + "reference": "5cf83dea155ae9666dd491470d760c126e4dab98" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/security-bundle/zipball/5cf83dea155ae9666dd491470d760c126e4dab98", + "reference": "5cf83dea155ae9666dd491470d760c126e4dab98", + "shasum": "" + }, + "require": { + "ext-xml": "*", + "php": "^7.2.5", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/http-kernel": "^5.0", + "symfony/security-core": "^4.4|^5.0", + "symfony/security-csrf": "^4.4|^5.0", + "symfony/security-guard": "^4.4|^5.0", + "symfony/security-http": "^4.4.1|^5.0.1" + }, + "conflict": { + "symfony/browser-kit": "<4.4", + "symfony/console": "<4.4", + "symfony/framework-bundle": "<4.4", + "symfony/ldap": "<4.4", + "symfony/twig-bundle": "<4.4" + }, + "require-dev": { + "doctrine/doctrine-bundle": "^1.5|^2.0", + "symfony/asset": "^4.4|^5.0", + "symfony/browser-kit": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/css-selector": "^4.4|^5.0", + "symfony/dom-crawler": "^4.4|^5.0", + "symfony/expression-language": "^4.4|^5.0", + "symfony/form": "^4.4|^5.0", + "symfony/framework-bundle": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0", + "symfony/translation": "^4.4|^5.0", + "symfony/twig-bridge": "^4.4|^5.0", + "symfony/twig-bundle": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0", + "twig/twig": "^2.10|^3.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\SecurityBundle\\": "" + }, + "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": "Symfony SecurityBundle", + "homepage": "https://symfony.com", + "time": "2019-12-16T10:47:49+00:00" + }, + { + "name": "symfony/security-core", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/security-core.git", + "reference": "4fa0454de2fab0f6c2e9990976d8872b16a0e0a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/security-core/zipball/4fa0454de2fab0f6c2e9990976d8872b16a0e0a9", + "reference": "4fa0454de2fab0f6c2e9990976d8872b16a0e0a9", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/event-dispatcher-contracts": "^1.1|^2", + "symfony/service-contracts": "^1.1.6|^2" + }, + "conflict": { + "symfony/event-dispatcher": "<4.4", + "symfony/ldap": "<4.4", + "symfony/security-guard": "<4.4" + }, + "require-dev": { + "psr/container": "^1.0", + "psr/log": "~1.0", + "symfony/event-dispatcher": "^4.4|^5.0", + "symfony/expression-language": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/ldap": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0" + }, + "suggest": { + "psr/container-implementation": "To instantiate the Security class", + "symfony/event-dispatcher": "", + "symfony/expression-language": "For using the expression voter", + "symfony/http-foundation": "", + "symfony/ldap": "For using LDAP integration", + "symfony/validator": "For using the user password constraint" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Security\\Core\\": "" + }, + "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": "Symfony Security Component - Core Library", + "homepage": "https://symfony.com", + "time": "2019-12-16T11:08:25+00:00" + }, + { + "name": "symfony/security-csrf", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/security-csrf.git", + "reference": "df14c3ebed8ed99750e8d27a6333918f80b5a8ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/security-csrf/zipball/df14c3ebed8ed99750e8d27a6333918f80b5a8ea", + "reference": "df14c3ebed8ed99750e8d27a6333918f80b5a8ea", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/security-core": "^4.4|^5.0" + }, + "conflict": { + "symfony/http-foundation": "<4.4" + }, + "require-dev": { + "symfony/http-foundation": "^4.4|^5.0" + }, + "suggest": { + "symfony/http-foundation": "For using the class SessionTokenStorage." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Security\\Csrf\\": "" + }, + "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": "Symfony Security Component - CSRF Library", + "homepage": "https://symfony.com", + "time": "2019-11-18T17:27:11+00:00" + }, + { + "name": "symfony/security-guard", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/security-guard.git", + "reference": "3e724cb9c186986e66ca2c1aaaba16fe4aa9abf9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/security-guard/zipball/3e724cb9c186986e66ca2c1aaaba16fe4aa9abf9", + "reference": "3e724cb9c186986e66ca2c1aaaba16fe4aa9abf9", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/security-core": "^5.0", + "symfony/security-http": "^4.4.1|^5.0.1" + }, + "require-dev": { + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Security\\Guard\\": "" + }, + "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": "Symfony Security Component - Guard", + "homepage": "https://symfony.com", + "time": "2019-11-30T14:12:50+00:00" + }, + { + "name": "symfony/security-http", + "version": "v5.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/security-http.git", + "reference": "64afb9eb9161c65f87de6fc31e3633843bddc02a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/security-http/zipball/64afb9eb9161c65f87de6fc31e3633843bddc02a", + "reference": "64afb9eb9161c65f87de6fc31e3633843bddc02a", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/security-core": "^4.4|^5.0" + }, + "conflict": { + "symfony/security-csrf": "<4.4" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/routing": "^4.4|^5.0", + "symfony/security-csrf": "^4.4|^5.0" + }, + "suggest": { + "symfony/routing": "For using the HttpUtils class to create sub-requests, redirect the user, and match URLs", + "symfony/security-csrf": "For using tokens to protect authentication/logout attempts" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Security\\Http\\": "" + }, + "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": "Symfony Security Component - HTTP Integration", + "homepage": "https://symfony.com", + "time": "2019-12-16T10:47:49+00:00" + }, { "name": "symfony/service-contracts", "version": "v2.0.1", @@ -4294,7 +4628,128 @@ "time": "2019-11-27T19:40:53+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "nikic/php-parser", + "version": "v4.3.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "0.0.5", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2019-11-08T13:50:10+00:00" + }, + { + "name": "symfony/maker-bundle", + "version": "v1.14.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/maker-bundle.git", + "reference": "c864e7f9b8d1e1f5f60acc3beda11299f637aded" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/maker-bundle/zipball/c864e7f9b8d1e1f5f60acc3beda11299f637aded", + "reference": "c864e7f9b8d1e1f5f60acc3beda11299f637aded", + "shasum": "" + }, + "require": { + "doctrine/inflector": "^1.2", + "nikic/php-parser": "^4.0", + "php": "^7.0.8", + "symfony/config": "^3.4|^4.0|^5.0", + "symfony/console": "^3.4|^4.0|^5.0", + "symfony/dependency-injection": "^3.4|^4.0|^5.0", + "symfony/filesystem": "^3.4|^4.0|^5.0", + "symfony/finder": "^3.4|^4.0|^5.0", + "symfony/framework-bundle": "^3.4|^4.0|^5.0", + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "require-dev": { + "doctrine/doctrine-bundle": "^1.8|^2.0", + "doctrine/orm": "^2.3", + "friendsofphp/php-cs-fixer": "^2.8", + "friendsoftwig/twigcs": "^3.1.2", + "symfony/http-client": "^4.3|^5.0", + "symfony/phpunit-bridge": "^4.3|^5.0", + "symfony/process": "^3.4|^4.0|^5.0", + "symfony/security-core": "^3.4|^4.0|^5.0", + "symfony/yaml": "^3.4|^4.0|^5.0" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Bundle\\MakerBundle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.", + "homepage": "https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html", + "keywords": [ + "code generator", + "generator", + "scaffold", + "scaffolding" + ], + "time": "2019-11-07T00:56:03+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/config/bundles.php b/config/bundles.php index ae2fcb64e122ee731fb2715c3de63306841b9db9..ab87bb6263b342329d24df9b0454940d8ed162e9 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -6,4 +6,6 @@ return [ Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], ]; diff --git a/src/Entity/AdminUser.php b/src/Entity/AdminUser.php new file mode 100644 index 0000000000000000000000000000000000000000..6bbae85bdb6b85917ecf6a73d17b1a200c3958d8 --- /dev/null +++ b/src/Entity/AdminUser.php @@ -0,0 +1,109 @@ +<?php + +namespace App\Entity; + +use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Security\Core\User\UserInterface; + +/** + * @ORM\Entity(repositoryClass="App\Repository\AdminUserRepository") + * @ORM\Table(name="mls_admin_user") + */ +class AdminUser implements UserInterface +{ + /** + * @ORM\Id() + * @ORM\GeneratedValue() + * @ORM\Column(type="integer") + */ + protected int $id; + + /** + * @ORM\Column(type="string", length=180, unique=true, nullable=false) + */ + protected string $username; + + /** + * @ORM\Column(type="json") + */ + protected array $roles = []; + + /** + * @var string The hashed password + * @ORM\Column(type="string", nullable=false) + */ + protected string $password; + + public function getId(): ?int + { + return $this->id; + } + + /** + * A visual identifier that represents this user. + * + * @see UserInterface + */ + public function getUsername(): string + { + return (string) $this->username; + } + + public function setUsername(string $username): self + { + $this->username = $username; + + return $this; + } + + /** + * @see UserInterface + */ + public function getRoles(): array + { + $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; + } + + /** + * @see UserInterface + */ + public function getPassword(): string + { + return (string) $this->password; + } + + public function setPassword(string $password): self + { + $this->password = $password; + + return $this; + } + + /** + * @see UserInterface + */ + public function getSalt() + { + // not needed when using the "bcrypt" algorithm in security.yaml + } + + /** + * @see UserInterface + */ + public function eraseCredentials() + { + // If you store any temporary, sensitive data on the user, clear it here + // $this->plainPassword = null; + } +} diff --git a/src/Entity/Answer.php b/src/Entity/Answer.php index 49f5e98b52daabb7c4b0cdc4b996b5452217ee28..fdd59ca015b6d62b7463da81d84681fb067e9438 100644 --- a/src/Entity/Answer.php +++ b/src/Entity/Answer.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; /** * Class Answer * @ORM\Entity - * @ORM\Table(name="answer") + * @ORM\Table(name="mls_answer") * @package App\Entity */ class Answer diff --git a/src/Entity/Question.php b/src/Entity/Question.php index 3a97d2bfa53eafdd579dcea5a1bf13b94d5b8cd5..73478328c74289d4b3fe4f4e263bc46d65441d03 100644 --- a/src/Entity/Question.php +++ b/src/Entity/Question.php @@ -10,7 +10,7 @@ use Symfony\Component\Routing\Exception\InvalidParameterException; /** * Class Question * @ORM\Entity(repositoryClass="App\Repository\QuestionRepository") - * @ORM\Table(name="question") + * @ORM\Table(name="mls_question") * @package App\Entity */ class Question diff --git a/src/Entity/Topic.php b/src/Entity/Topic.php index fcb0e04977a734b27c92e15db2b440a0b7811723..7696578cf6d6694051007101a3d934ec0d1341cd 100644 --- a/src/Entity/Topic.php +++ b/src/Entity/Topic.php @@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM; /** * Class Topic * @ORM\Entity(repositoryClass="App\Repository\TopicRepository") - * @ORM\Table(name="topic") + * @ORM\Table(name="mls_topic") * @package App\Entity */ class Topic diff --git a/src/Migrations/Version20200108172607.php b/src/Migrations/Version20200108172607.php index c3e7b327dd443245e7f7bd98123bc28879f167d8..2d0b6b14501757505c6a5aede4cc3e0fdcab647f 100644 --- a/src/Migrations/Version20200108172607.php +++ b/src/Migrations/Version20200108172607.php @@ -27,9 +27,20 @@ final class Version20200108172607 extends AbstractMigration } catch (DBALException $e) { $this->abortIf(true, sprintf('Migration failed! Reason: %s', $e->getMessage())); } - $this->addSql(' - CREATE TABLE `topic` ( + CREATE TABLE `mls_admin_user` ( + `id` INT AUTO_INCREMENT NOT NULL, + `username` VARCHAR(180) NOT NULL, + `roles` JSON NOT NULL, + `password` VARCHAR(255) NOT NULL, + PRIMARY KEY(`id`) + ) + DEFAULT CHARACTER SET utf8mb4 + COLLATE `utf8mb4_unicode_ci` + ENGINE = InnoDB + '); + $this->addSql(' + CREATE TABLE `mls_topic` ( `id` INT AUTO_INCREMENT NOT NULL, `label` VARCHAR(20) NOT NULL, PRIMARY KEY(`id`) @@ -39,14 +50,14 @@ final class Version20200108172607 extends AbstractMigration ENGINE = InnoDB '); $this->addSql(' - CREATE TABLE `question` ( + CREATE TABLE `mls_question` ( `id` INT AUTO_INCREMENT NOT NULL, `topic_id` INT NOT NULL, `label` VARCHAR(1024) NOT NULL, `structure_type` VARCHAR(10) NOT NULL, `content_type` VARCHAR(20) NOT NULL, - INDEX IDX_B6F7494E1F55203D (`topic_id`), - FOREIGN KEY FK_B6F7494E1F55203D (`topic_id`) REFERENCES `topic`(`id`), + INDEX `IDX_B6F7494E1F55203D` (`topic_id`), + CONSTRAINT `FK_B6F7494E1F55203D` FOREIGN KEY (`topic_id`) REFERENCES `mls_topic`(`id`) ON DELETE CASCADE, PRIMARY KEY(`id`) ) DEFAULT CHARACTER SET utf8mb4 @@ -54,13 +65,13 @@ final class Version20200108172607 extends AbstractMigration ENGINE = InnoDB '); $this->addSql(' - CREATE TABLE `answer` ( + CREATE TABLE `mls_answer` ( `id` INT AUTO_INCREMENT NOT NULL, `question_id` INT NOT NULL, `label` VARCHAR(1024) NOT NULL, `is_correct` BOOL NOT NULL, - INDEX IDX_DADD4A251E27F6BF (`question_id`), - FOREIGN KEY FK_DADD4A251E27F6BF (`question_id`) REFERENCES `question`(`id`), + INDEX `IDX_DADD4A251E27F6BF` (`question_id`), + CONSTRAINT `FK_DADD4A251E27F6BF` FOREIGN KEY (`question_id`) REFERENCES `mls_question`(`id`) ON DELETE CASCADE, PRIMARY KEY(`id`) ) DEFAULT CHARACTER SET utf8mb4 @@ -80,10 +91,11 @@ final class Version20200108172607 extends AbstractMigration $this->abortIf(true, sprintf('Migration failed! Reason: %s', $e->getMessage())); } - $this->addSql('ALTER TABLE answer DROP FOREIGN KEY FK_DADD4A251E27F6BF'); - $this->addSql('ALTER TABLE question DROP FOREIGN KEY FK_B6F7494E1F55203D'); - $this->addSql('DROP TABLE answer'); - $this->addSql('DROP TABLE question'); - $this->addSql('DROP TABLE topic'); + $this->addSql('ALTER TABLE `mls_answer` DROP FOREIGN KEY `FK_DADD4A251E27F6BF`'); + $this->addSql('ALTER TABLE `mls_question` DROP FOREIGN KEY `FK_B6F7494E1F55203D`'); + $this->addSql('DROP TABLE `mls_answer`'); + $this->addSql('DROP TABLE `mls_question`'); + $this->addSql('DROP TABLE `mls_topic`'); + $this->addSql('DROP TABLE `mls_admin_user`'); } } diff --git a/src/Repository/AdminUserRepository.php b/src/Repository/AdminUserRepository.php new file mode 100644 index 0000000000000000000000000000000000000000..a76dcad9afc6043ff7b5f417420c845123c903c6 --- /dev/null +++ b/src/Repository/AdminUserRepository.php @@ -0,0 +1,67 @@ +<?php + +namespace App\Repository; + +use App\Entity\AdminUser; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Common\Persistence\ManagerRegistry; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; +use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; +use Symfony\Component\Security\Core\User\UserInterface; + +/** + * @method AdminUser|null find($id, $lockMode = null, $lockVersion = null) + * @method AdminUser|null findOneBy(array $criteria, array $orderBy = null) + * @method AdminUser[] findAll() + * @method AdminUser[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class AdminUserRepository extends ServiceEntityRepository implements PasswordUpgraderInterface +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, AdminUser::class); + } + + /** + * Used to upgrade (rehash) the user's password automatically over time. + */ + public function upgradePassword(UserInterface $user, string $newEncodedPassword): void + { + if (!$user instanceof User) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); + } + + $user->setPassword($newEncodedPassword); + $this->_em->persist($user); + $this->_em->flush(); + } + + // /** + // * @return AdminUser[] Returns an array of AdminUser objects + // */ + /* + public function findByExampleField($value) + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('a.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?AdminUser + { + return $this->createQueryBuilder('a') + ->andWhere('a.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/symfony.lock b/symfony.lock index 06bc1ebff2723754a2752141c8605cce7215a9fc..27a769d885236c11b4d182b30ba6c6de99c033eb 100644 --- a/symfony.lock +++ b/symfony.lock @@ -87,6 +87,9 @@ "laminas/laminas-zendframework-bridge": { "version": "1.0.1" }, + "nikic/php-parser": { + "version": "v4.3.0" + }, "ocramius/package-versions": { "version": "1.5.1" }, @@ -204,6 +207,15 @@ "symfony/intl": { "version": "v5.0.2" }, + "symfony/maker-bundle": { + "version": "1.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "1.0", + "ref": "fadbfe33303a76e25cb63401050439aa9b1a9c7f" + } + }, "symfony/mime": { "version": "v5.0.1" }, @@ -242,6 +254,30 @@ "./config/routes.yaml" ] }, + "symfony/security-bundle": { + "version": "4.4", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.4", + "ref": "30efd98dd3b4ead6e9ad4713b1efc43bbe94bf77" + }, + "files": [ + "./config/packages/security.yaml" + ] + }, + "symfony/security-core": { + "version": "v5.0.2" + }, + "symfony/security-csrf": { + "version": "v5.0.2" + }, + "symfony/security-guard": { + "version": "v5.0.2" + }, + "symfony/security-http": { + "version": "v5.0.2" + }, "symfony/service-contracts": { "version": "v2.0.1" },