From 8a0e27a287e1dec6d4b8a2f544978e815fb977ff Mon Sep 17 00:00:00 2001 From: Gnieark Date: Thu, 26 Dec 2019 16:55:43 +0100 Subject: [PATCH] wip --- config/routes.yaml | 11 +++++++- src/Controller/SecurityController.php | 36 ++++++++++++++++++++++++ src/Entity/User.php | 34 ++++++++++++++++++++++ src/Migrations/Version20191226142335.php | 35 +++++++++++++++++++++++ templates/base.html.twig | 1 + templates/security/register.html.twig | 8 ++++++ 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/Migrations/Version20191226142335.php create mode 100644 templates/security/register.html.twig diff --git a/config/routes.yaml b/config/routes.yaml index 3dc015f..cbfb37b 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -5,4 +5,13 @@ index: login: path: /login controller: App\Controller\SecurityController::login - methods: GET|POST \ No newline at end of file + methods: GET|POST + +register: + path: /register + controller: App\Controller\SecurityController::show_register_form + methods: GET|POST +register: + path: /register + controller: App\Controller\SecurityController::register + methods: POST \ No newline at end of file diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 0357ef2..2f14d46 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -4,6 +4,11 @@ namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\Extension\Core\Type\EmailType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use App\Entity\User; @@ -31,4 +36,35 @@ class SecurityController extends AbstractController { throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall'); } + + /** + * @Route("/register", name="register") + */ + + public function show_register_form() + { + return $this->render('security/register.html.twig', [ + 'form' => $this->get_registerform()->createView() + ]); + } + + private function get_registerform() + { + return $this->createFormBuilder() + ->add('email', EmailType::class) + ->add('password', PasswordType::class, []) + ->add('display_name', TextType::class,[]) + ->add('save', SubmitType::class) + ->getForm(); + + } + + public function register(Request $request, UserPasswordEncoderInterface $passwordEncoder) + { + $form = $this->get_registerform(); + $form->handleRequest($request); + + + } + } diff --git a/src/Entity/User.php b/src/Entity/User.php index fe4a565..f3f2077 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -33,6 +33,16 @@ class User implements UserInterface */ private $password; + /** + * @ORM\Column(type="boolean") + */ + private $active; + + /** + * @ORM\Column(type="string", length=255) + */ + private $display_name; + public function getId(): ?int { return $this->id; @@ -110,4 +120,28 @@ class User implements UserInterface // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } + + public function getActive(): ?bool + { + return $this->active; + } + + public function setActive(bool $active): self + { + $this->active = $active; + + return $this; + } + + public function getDisplayName(): ?string + { + return $this->display_name; + } + + public function setDisplayName(string $display_name): self + { + $this->display_name = $display_name; + + return $this; + } } diff --git a/src/Migrations/Version20191226142335.php b/src/Migrations/Version20191226142335.php new file mode 100644 index 0000000..2dd7beb --- /dev/null +++ b/src/Migrations/Version20191226142335.php @@ -0,0 +1,35 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE user ADD active TINYINT(1) NOT NULL, ADD display_name VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE user DROP active, DROP display_name'); + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index 043f42d..18e0f47 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -6,6 +6,7 @@ {% block stylesheets %}{% endblock %} +
{% block header %}

Resources booking manager

{% endblock %}
{% block body %}{% endblock %} {% block javascripts %}{% endblock %} diff --git a/templates/security/register.html.twig b/templates/security/register.html.twig new file mode 100644 index 0000000..67e4d59 --- /dev/null +++ b/templates/security/register.html.twig @@ -0,0 +1,8 @@ +{% extends 'base.html.twig' %} +{% block title %}Register{% endblock %} +{% block header %}

Register a new user

{% endblock %} +{% block body %} + +{{ form(form) }} + +{% endblock %}