diff --git a/composer.json b/composer.json index 384b2d4..f04c99c 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "symfony/proxy-manager-bridge": "5.2.*", "symfony/security-bundle": "5.2.*", "symfony/twig-bundle": "^5.2", + "symfony/validator": "5.2.*", "symfony/yaml": "5.2.*", "twig/extra-bundle": "^2.12|^3.0", "twig/twig": "^2.12|^3.0" diff --git a/composer.lock b/composer.lock index e90543e..f65bff1 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": "0474966a06e7b2b0454614e9b684fd7b", + "content-hash": "47f05c4f8f1d3ea9fca636127ecfd3d8", "packages": [ { "name": "composer/package-versions-deprecated", @@ -5893,6 +5893,115 @@ ], "time": "2021-03-21T16:15:38+00:00" }, + { + "name": "symfony/validator", + "version": "v5.2.9", + "source": { + "type": "git", + "url": "https://github.com/symfony/validator.git", + "reference": "3c16d6c2036190f9033643057168a6d8c5617886" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/validator/zipball/3c16d6c2036190f9033643057168a6d8c5617886", + "reference": "3c16d6c2036190f9033643057168a6d8c5617886", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php73": "~1.0", + "symfony/polyfill-php80": "^1.15", + "symfony/translation-contracts": "^1.1|^2" + }, + "conflict": { + "doctrine/lexer": "<1.0.2", + "phpunit/phpunit": "<5.4.3", + "symfony/dependency-injection": "<4.4", + "symfony/expression-language": "<5.1", + "symfony/http-kernel": "<4.4", + "symfony/intl": "<4.4", + "symfony/translation": "<4.4", + "symfony/yaml": "<4.4" + }, + "require-dev": { + "doctrine/annotations": "^1.10.4", + "doctrine/cache": "^1.0|^2.0", + "egulias/email-validator": "^2.1.10|^3", + "symfony/cache": "^4.4|^5.0", + "symfony/config": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/expression-language": "^5.1", + "symfony/finder": "^4.4|^5.0", + "symfony/http-client": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/intl": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", + "symfony/property-info": "^4.4|^5.0", + "symfony/translation": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0" + }, + "suggest": { + "egulias/email-validator": "Strict (RFC compliant) email validation", + "psr/cache-implementation": "For using the mapping cache.", + "symfony/config": "", + "symfony/expression-language": "For using the Expression validator and the ExpressionLanguageSyntax constraints", + "symfony/http-foundation": "", + "symfony/intl": "", + "symfony/property-access": "For accessing properties within comparison constraints", + "symfony/property-info": "To automatically add NotNull and Type constraints", + "symfony/translation": "For translating validation errors.", + "symfony/yaml": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Validator\\": "" + }, + "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 tools to validate values", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/validator/tree/v5.2.9" + }, + "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": "2021-05-17T20:21:27+00:00" + }, { "name": "symfony/var-dumper", "version": "v5.2.8", diff --git a/config/packages/test/validator.yaml b/config/packages/test/validator.yaml new file mode 100644 index 0000000..1e5ab78 --- /dev/null +++ b/config/packages/test/validator.yaml @@ -0,0 +1,3 @@ +framework: + validation: + not_compromised_password: false diff --git a/config/packages/validator.yaml b/config/packages/validator.yaml new file mode 100644 index 0000000..350786a --- /dev/null +++ b/config/packages/validator.yaml @@ -0,0 +1,8 @@ +framework: + validation: + email_validation_mode: html5 + + # Enables validator auto-mapping support. + # For instance, basic validation constraints will be inferred from Doctrine's metadata. + #auto_mapping: + # App\Entity\: [] diff --git a/src/Controller/BlogController.php b/src/Controller/BlogController.php index bb88a12..cfd49f2 100644 --- a/src/Controller/BlogController.php +++ b/src/Controller/BlogController.php @@ -2,17 +2,38 @@ namespace App\Controller; +use App\Entity\Blog; +use App\Repository\BlogRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +/** + * Class BlogController + * @package App\Controller + */ class BlogController extends AbstractController { - #[Route('/', name: 'blog')] - public function index(): Response - { - return $this->render('blog/index.html.twig', [ - 'controller_name' => 'BlogController', - ]); - } + #[Route('/', name: 'blogs')] + public function index(BlogRepository $blogRepository): Response + { + return $this->render('blog/index.html.twig', [ + 'blogs' => $blogRepository->findAll() + ]); + } + + + /** + * @param $id + * @param \App\Repository\BlogRepository $blogRepository + * + * @return \Symfony\Component\HttpFoundation\Response + */ + #[Route('/blog/{id}', name: 'blog')] + public function show($id, BlogRepository $blogRepository): Response + { + return $this->render('blog/show.html.twig', [ + 'blog' => $blogRepository->findOneBy(['id' => $id]) + ]); + } } diff --git a/src/Security/AppAuthenticator.php b/src/Security/AppAuthenticator.php index f5c02cc..32229b2 100644 --- a/src/Security/AppAuthenticator.php +++ b/src/Security/AppAuthenticator.php @@ -147,8 +147,8 @@ class AppAuthenticator extends AbstractFormLoginAuthenticator implements Passwor */ public function checkCredentials($credentials, UserInterface $user) { - return true; - //return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); + //return true; + return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); } /** @@ -165,7 +165,7 @@ class AppAuthenticator extends AbstractFormLoginAuthenticator implements Passwor return new RedirectResponse($targetPath); } - return new RedirectResponse($this->urlGenerator->generate('blog')); + return new RedirectResponse($this->urlGenerator->generate('blogs')); } protected function getLoginUrl() diff --git a/symfony.lock b/symfony.lock index 4784e3f..5412c6b 100644 --- a/symfony.lock +++ b/symfony.lock @@ -350,6 +350,19 @@ "symfony/uid": { "version": "v5.2.6" }, + "symfony/validator": { + "version": "4.3", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "master", + "version": "4.3", + "ref": "d902da3e4952f18d3bf05aab29512eb61cabd869" + }, + "files": [ + "config/packages/test/validator.yaml", + "config/packages/validator.yaml" + ] + }, "symfony/var-dumper": { "version": "v5.2.8" }, diff --git a/templates/blog/index.html.twig b/templates/blog/index.html.twig index c50aaac..b994aba 100644 --- a/templates/blog/index.html.twig +++ b/templates/blog/index.html.twig @@ -3,18 +3,10 @@ {% block title %}Hello BlogController!{% endblock %} {% block body %} - + {% for blog in blogs %} +
{{ blog.teaser }}
-src/Controller/BlogController.php
templates/blog/index.html.twig