From 51946809239a4c5241ed6cf3929beb798b650087 Mon Sep 17 00:00:00 2001 From: Justina Zidziunaite Date: Tue, 26 Nov 2019 00:06:30 +0200 Subject: [PATCH 1/6] Homework 3 tasks --- config/packages/easy_admin.yaml | 2 ++ src/Entity/User.php | 15 ++++++++++ src/Form/RegistrationFormType.php | 1 + src/Migrations/Version20191125215327.php | 35 +++++++++++++++++++++++ templates/base.html.twig | 3 +- templates/registration/register.html.twig | 1 + templates/security/profile.html.twig | 5 +++- 7 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/Migrations/Version20191125215327.php diff --git a/config/packages/easy_admin.yaml b/config/packages/easy_admin.yaml index a34b62ecb..92c039863 100644 --- a/config/packages/easy_admin.yaml +++ b/config/packages/easy_admin.yaml @@ -10,6 +10,7 @@ easy_admin: - 'username' - { property: 'roles', template: 'admin/user/roles-type-read.html.twig' } - { property: 'homepage', type: 'url' } + - { property: 'linkedin', type: 'url' } - { property: 'password', template: 'admin/user/password-read.html.twig' } form: fields: @@ -17,6 +18,7 @@ easy_admin: - { property: 'roles', type: 'collection' } - { property: 'plainPassword', type: 'password' } - { property: 'homepage', type: 'url' } + - { property: 'linkedin', type: 'url' } user: name_property_path: "email" \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php index cac6aafc7..f047d683f 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -50,6 +50,8 @@ class User implements UserInterface */ private $homepage = ""; + private $linkedin; + public function getId(): ?int { return $this->id; @@ -187,4 +189,17 @@ public function setHomepage(?string $homepage): self return $this; } + + public function setLinkedin(?string $linkedin): self + { + $this->linkedin = $linkedin; + + return $this; + } + + public function getLinkedin(): ?string + { + return $this->linkedin; + } + } diff --git a/src/Form/RegistrationFormType.php b/src/Form/RegistrationFormType.php index 31024cd40..abd32eb31 100644 --- a/src/Form/RegistrationFormType.php +++ b/src/Form/RegistrationFormType.php @@ -36,6 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ], ]) ->add('homepage', UrlType::class, ['required' => false]) + ->add('linkedin', UrlType::class, ['required' => false]) ->add('agreeTerms', CheckboxType::class, [ 'mapped' => false, 'constraints' => [ diff --git a/src/Migrations/Version20191125215327.php b/src/Migrations/Version20191125215327.php new file mode 100644 index 000000000..54da1e085 --- /dev/null +++ b/src/Migrations/Version20191125215327.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 linkedin VARCHAR(255) DEFAULT NULL, CHANGE roles roles JSON NOT NULL, CHANGE homepage homepage VARCHAR(255) DEFAULT NULL, CHANGE password_changed password_changed DATETIME DEFAULT 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 linkedin, CHANGE roles roles LONGTEXT NOT NULL COLLATE utf8mb4_bin, CHANGE password_changed password_changed DATETIME DEFAULT \'NULL\', CHANGE homepage homepage VARCHAR(255) DEFAULT \'NULL\' COLLATE utf8mb4_unicode_ci'); + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index eb61ed532..2e2b0c99c 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -32,10 +32,11 @@ + {% if is_granted('ROLE_ADMIN') %} - + {% endif %} {% else %}