diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig index 7e93622..bc0982d 100644 --- a/app/Resources/views/base.html.twig +++ b/app/Resources/views/base.html.twig @@ -49,7 +49,7 @@
{% if user is defined and user %}
- {{ user.username }}
+ {{ user.username }}
| Odhlásit
{% else %}
Přihlásit
diff --git a/app/Resources/views/user/profile.html.twig b/app/Resources/views/user/profile.html.twig
new file mode 100644
index 0000000..0c2cea5
--- /dev/null
+++ b/app/Resources/views/user/profile.html.twig
@@ -0,0 +1,12 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+ {{ form_start(form) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.phone) }}
+ {{ form_row(form.username) }}
+ {{ form_row(form.address) }}
+
+
+ {{ form_end(form) }}
+{% endblock %}
\ No newline at end of file
diff --git a/app/config/security.yml b/app/config/security.yml
index 82c6691..f8ae745 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -9,6 +9,23 @@ security:
entity: { class: AppBundle:User, property: username }
firewalls:
+ user_area:
+ pattern: ^/profile
+
+ form_login:
+ check_path: user_login
+ login_path: user_login
+ csrf_token_generator: security.csrf.token_manager
+ default_target_path: /
+
+ logout:
+ # The route name the user can go to in order to logout
+ path: user_logout
+ # The name of the route to redirect to after logging out
+ target: homepage
+
+ context: primary_auth
+
secured_area:
pattern: ^/
@@ -24,4 +41,6 @@ security:
# The route name the user can go to in order to logout
path: user_logout
# The name of the route to redirect to after logging out
- target: homepage
\ No newline at end of file
+ target: homepage
+
+ context: primary_auth
diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php
index d0958e3..728bba5 100644
--- a/src/AppBundle/Controller/UserController.php
+++ b/src/AppBundle/Controller/UserController.php
@@ -2,6 +2,7 @@
namespace AppBundle\Controller;
use AppBundle\Entity\User;
use AppBundle\Facade\UserFacade;
+use AppBundle\FormType\PersonalInfoFormType;
use AppBundle\FormType\RegistrationFormType;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
@@ -91,6 +92,42 @@ public function loginAction()
];
}
+ /**
+ * @Route("/profile", name="user_profile")
+ * @Template("user/profile.html.twig")
+ *
+ * @param Request $request
+ * @return array|RedirectResponse
+ */
+ public function profileAction(Request $request)
+ {
+ // 1) build the form
+ $user = $this->userFacade->getUser();
+ $form = $this->formFactory->create(PersonalInfoFormType::class, $user);
+
+ // 2) handle the submit (will only happen on POST)
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+
+ if ($address = $user->getAddress()) {
+ $this->entityManager->persist($address);
+ $this->entityManager->flush($address);
+ }
+
+ $this->entityManager->persist($user);
+ $this->entityManager->flush($user);
+
+ // ... do any other work - like sending them an email, etc
+ // maybe set a "flash" success message for the user
+ return RedirectResponse::create($this->router->generate("homepage"));
+ }
+
+ return [
+ "user" => $this->userFacade->getUser(),
+ "form" => $form->createView(),
+ ];
+ }
+
/**
* @Route("/odhlasit", name="user_logout")
*/
diff --git a/src/AppBundle/Entity/Address.php b/src/AppBundle/Entity/Address.php
new file mode 100644
index 0000000..4ac3b21
--- /dev/null
+++ b/src/AppBundle/Entity/Address.php
@@ -0,0 +1,98 @@
+id;
+ }
+
+ /**
+ * @return string
+ */
+ public function getStreet()
+ {
+ return $this->street;
+ }
+
+ /**
+ * @param string $street
+ */
+ public function setStreet(string $street)
+ {
+ $this->street = $street;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCity()
+ {
+ return $this->city;
+ }
+
+ /**
+ * @param string $city
+ */
+ public function setCity(string $city)
+ {
+ $this->city = $city;
+ }
+
+ /**
+ * @return string
+ */
+ public function getZip()
+ {
+ return $this->zip;
+ }
+
+ /**
+ * @param string $zip
+ */
+ public function setZip(string $zip)
+ {
+ $this->zip = $zip;
+ }
+}
\ No newline at end of file
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 5dd2213..422fe68 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -36,7 +36,25 @@ class User implements UserInterface
private $password;
/**
- * @Assert\NotBlank()
+ * @ORM\Column(type="string", length=255, name="name", nullable=true)
+ * @Assert\Length(max=4096)
+ */
+ private $name;
+
+ /**
+ * @ORM\Column(type="string", length=20, name="phone", nullable=true)
+ * @Assert\Length(max=4096)
+ */
+ private $phone;
+
+ /**
+ * @ORM\OneToOne(targetEntity="Address")
+ * @ORM\JoinColumn(name="address_id", referencedColumnName="id")
+ * @var Address
+ */
+ private $address;
+
+ /**
* @Assert\Length(max=4096)
*/
private $plainPassword;
@@ -129,4 +147,51 @@ public function eraseCredentials()
return;
}
+ /**
+ * @return mixed
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param mixed $name
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getPhone()
+ {
+ return $this->phone;
+ }
+
+ /**
+ * @param mixed $phone
+ */
+ public function setPhone($phone)
+ {
+ $this->phone = $phone;
+ }
+
+ /**
+ * @return Address
+ */
+ public function getAddress()
+ {
+ return $this->address;
+ }
+
+ /**
+ * @param Address $address
+ */
+ public function setAddress($address)
+ {
+ $this->address = $address;
+ }
}
diff --git a/src/AppBundle/FormType/AddressFormType.php b/src/AppBundle/FormType/AddressFormType.php
new file mode 100644
index 0000000..10d95f8
--- /dev/null
+++ b/src/AppBundle/FormType/AddressFormType.php
@@ -0,0 +1,42 @@
+add('street', TextType::class, [
+ "label" => "Ulice",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add('city', TextType::class, [
+ "label" => "Město",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add('zip', TextType::class, [
+ "label" => "PSČ",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => Address::class,
+ ));
+ }
+}
diff --git a/src/AppBundle/FormType/PersonalInfoFormType.php b/src/AppBundle/FormType/PersonalInfoFormType.php
new file mode 100644
index 0000000..4499d35
--- /dev/null
+++ b/src/AppBundle/FormType/PersonalInfoFormType.php
@@ -0,0 +1,44 @@
+add("name", TextType::class, [
+ "label" => "Jméno",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("phone", TextType::class, [
+ "label" => "Telefon",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("username", EmailType::class, [
+ "label" => "E-mail",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add('address', AddressFormType::class);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+}