This commit is contained in:
Gnieark 2019-12-26 16:55:43 +01:00
parent cc20f83fc2
commit 8a0e27a287
6 changed files with 124 additions and 1 deletions

View File

@ -6,3 +6,12 @@ login:
path: /login path: /login
controller: App\Controller\SecurityController::login controller: App\Controller\SecurityController::login
methods: GET|POST 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

View File

@ -4,6 +4,11 @@ namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; 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\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use App\Entity\User; 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'); 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);
}
} }

View File

@ -33,6 +33,16 @@ class User implements UserInterface
*/ */
private $password; private $password;
/**
* @ORM\Column(type="boolean")
*/
private $active;
/**
* @ORM\Column(type="string", length=255)
*/
private $display_name;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -110,4 +120,28 @@ class User implements UserInterface
// If you store any temporary, sensitive data on the user, clear it here // If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null; // $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;
}
} }

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20191226142335 extends AbstractMigration
{
public function getDescription() : string
{
return '';
}
public function up(Schema $schema) : void
{
// this up() 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 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');
}
}

View File

@ -6,6 +6,7 @@
{% block stylesheets %}{% endblock %} {% block stylesheets %}{% endblock %}
</head> </head>
<body> <body>
<header>{% block header %}<h1>Resources booking manager</h1>{% endblock %}</header>
{% block body %}{% endblock %} {% block body %}{% endblock %}
{% block javascripts %}{% endblock %} {% block javascripts %}{% endblock %}
</body> </body>

View File

@ -0,0 +1,8 @@
{% extends 'base.html.twig' %}
{% block title %}Register{% endblock %}
{% block header %}<h1>Register a new user</h1>{% endblock %}
{% block body %}
{{ form(form) }}
{% endblock %}