diff --git a/migrations/Version20210422155430.php b/migrations/Version20210422155430.php new file mode 100644 index 0000000..8317eee --- /dev/null +++ b/migrations/Version20210422155430.php @@ -0,0 +1,34 @@ +addSql('ALTER TABLE "user" ADD username VARCHAR(255) NOT NULL DEFAULT \'\''); + $this->addSql('ALTER TABLE "user" ALTER is_verified DROP DEFAULT'); + } + + public function down(Schema $schema) : void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('CREATE SCHEMA public'); + $this->addSql('ALTER TABLE "user" DROP username'); + $this->addSql('ALTER TABLE "user" ALTER is_verified SET DEFAULT \'true\''); + } +} diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 92450f6..c495a04 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -15,4 +15,12 @@ class AppController extends AbstractController 'controller_name' => 'AppController', ]); } + + #[Route('/user', name: 'user_page')] + public function user(): Response + { + return $this->render('app/index.html.twig', [ + 'user' => $this->getUser(), + ]); + } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 6604ed3..51efa46 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -42,6 +42,11 @@ class User implements UserInterface */ private $isVerified = false; + /** + * @ORM\Column(type="string", length=255) + */ + private $username; + public function getId(): ?int { return $this->id; @@ -66,7 +71,7 @@ class User implements UserInterface */ public function getUsername(): string { - return (string) $this->email; + return (string) $this->username; } /** @@ -134,4 +139,11 @@ class User implements UserInterface return $this; } + + public function setUsername(string $username): self + { + $this->username = $username; + + return $this; + } } diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php index 80102b9..24ff915 100644 --- a/src/Form/RegistrationFormType.php +++ b/src/Form/RegistrationFormType.php @@ -18,6 +18,7 @@ class RegistrationFormType extends AbstractType { $builder ->add('email') + ->add('username') ->add('agreeTerms', CheckboxType::class, [ 'mapped' => false, 'constraints' => [ diff --git a/templates/app/index.html.twig b/templates/app/index.html.twig index 6245d25..4fb7e9c 100644 --- a/templates/app/index.html.twig +++ b/templates/app/index.html.twig @@ -9,12 +9,6 @@
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - +

Hello {{ user.username }}!

{% endblock %} diff --git a/templates/registration/register.html.twig b/templates/registration/register.html.twig index 9a619fd..ed35d93 100644 --- a/templates/registration/register.html.twig +++ b/templates/registration/register.html.twig @@ -11,6 +11,7 @@ {{ form_start(registrationForm) }} {{ form_row(registrationForm.email) }} + {{ form_row(registrationForm.username) }} {{ form_row(registrationForm.plainPassword, { label: 'Password' }) }}