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/address.html.twig b/app/Resources/views/user/address.html.twig
new file mode 100644
index 0000000..17f15ad
--- /dev/null
+++ b/app/Resources/views/user/address.html.twig
@@ -0,0 +1,23 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+
+
+
+
+ {{ form_errors(form) }}
+
+ {{ form_start(form) }}
+ {{ form_row(form.street) }}
+ {{ form_row(form.city) }}
+ {{ form_row(form.zipcode) }}
+
+ {{ form_row(form.submit) }}
+ {{ form_end(form) }}
+
+{% endblock %}
+
diff --git a/app/Resources/views/user/password.html.twig b/app/Resources/views/user/password.html.twig
new file mode 100644
index 0000000..d09107a
--- /dev/null
+++ b/app/Resources/views/user/password.html.twig
@@ -0,0 +1,20 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+
+
+
+
+ {{ form_start(form) }}
+ {{ form_row(form.plainPassword.first) }}
+ {{ form_row(form.plainPassword.second) }}
+
+ {{ form_row(form.submit) }}
+ {{ form_end(form) }}
+
+{% endblock %}
+
diff --git a/app/Resources/views/user/profile.html.twig b/app/Resources/views/user/profile.html.twig
new file mode 100644
index 0000000..3c225f1
--- /dev/null
+++ b/app/Resources/views/user/profile.html.twig
@@ -0,0 +1,23 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+
+
+
+
+ {{ form_errors(form) }}
+
+ {{ form_start(form) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.surname) }}
+ {{ form_row(form.phone) }}
+
+ {{ form_row(form.submit) }}
+ {{ form_end(form) }}
+
+{% endblock %}
+
diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php
index d0958e3..29fd8c9 100644
--- a/src/AppBundle/Controller/UserController.php
+++ b/src/AppBundle/Controller/UserController.php
@@ -2,7 +2,10 @@
namespace AppBundle\Controller;
use AppBundle\Entity\User;
use AppBundle\Facade\UserFacade;
+use AppBundle\FormType\AddressFormType;
+use AppBundle\FormType\PasswordFormType;
use AppBundle\FormType\RegistrationFormType;
+use AppBundle\FormType\UserFormType;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
@@ -28,13 +31,13 @@ class UserController
private $router;
public function __construct(
- UserFacade $userFacade,
+ UserFacade $userFacade,
FormFactory $formFactory,
PasswordEncoderInterface $passwordEncoder,
EntityManager $entityManager,
RouterInterface $router
) {
- $this->userFacade = $userFacade;
+ $this->userFacade = $userFacade;
$this->formFactory = $formFactory;
$this->passwordEncoder = $passwordEncoder;
$this->entityManager = $entityManager;
@@ -112,5 +115,104 @@ public function superSecretAction()
"user" => $this->userFacade->getUser(),
];
}
-
+
+ /**
+ * @Route("/user/profile", name="user_profile")
+ * @param Request $request
+ * @return RedirectResponse|array
+ * @Template("user/profile.html.twig")
+ */
+ public function profileAction(Request $request)
+ {
+ $user = $this->userFacade->getUser();
+
+ if (!$user) {
+ throw new UnauthorizedHttpException("Přihlašte se");
+ }
+
+ $form = $this->formFactory->create(UserFormType::class, $user);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted()) {
+
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ return RedirectResponse::create($this->router->generate("user_profile"));
+ }
+
+ return [
+ "form" => $form->createView(),
+ "user" => $user,
+ ];
+ }
+
+ /**
+ * @Route("/user/password", name="user_password")
+ * @param Request $request
+ * @return RedirectResponse|array
+ * @Template("user/password.html.twig")
+ */
+ public function passwordAction(Request $request)
+ {
+ $user = $this->userFacade->getUser();
+
+ if (!$user) {
+ throw new UnauthorizedHttpException("Přihlašte se");
+ }
+
+ $form = $this->formFactory->create(PasswordFormType::class, $user);
+
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+
+ $user->setPassword(
+ $this->passwordEncoder->encodePassword($user->getPlainPassword(), null)
+ );
+
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ return RedirectResponse::create($this->router->generate("user_password"));
+ }
+
+ return [
+ "form" => $form->createView(),
+ "user" => $user,
+ ];
+ }
+
+ /**
+ * @Route("/user/address", name="user_address")
+ * @param Request $request
+ * @return RedirectResponse|array
+ * @Template("user/address.html.twig")
+ */
+ public function addressAction(Request $request)
+ {
+ $user = $this->userFacade->getUser();
+
+ if (!$user) {
+ throw new UnauthorizedHttpException("Přihlašte se");
+ }
+
+ $form = $this->formFactory->create(AddressFormType::class, $user);
+
+ $form->handleRequest($request);
+ if ($form->isSubmitted()) {
+
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ return RedirectResponse::create($this->router->generate("user_address"));
+ }
+
+ return [
+ "form" => $form->createView(),
+ "user" => $user,
+ ];
+ }
+
+
}
\ No newline at end of file
diff --git a/src/AppBundle/Entity/Address.php b/src/AppBundle/Entity/Address.php
new file mode 100644
index 0000000..e4615a3
--- /dev/null
+++ b/src/AppBundle/Entity/Address.php
@@ -0,0 +1,151 @@
+
+ * @ORM\Table(name="address")
+ * @ORM\Entity(repositoryClass="AppBundle\Repository\AddressRepository")
+ */
+class Address
+{
+ /**
+ * @var int
+ * @ORM\Column(name="id", type="integer")
+ * @ORM\Id
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ private $id;
+
+ /**
+ * @var User
+ * @ORM\ManyToOne(targetEntity="User")
+ */
+ private $user;
+
+ /**
+ * @var string
+ * @ORM\Column(name="street", type="string", length=255)
+ */
+ private $street;
+
+ /**
+ * @var string
+ * @ORM\Column(name="city", type="string", length=255)
+ */
+ private $city;
+
+ /**
+ * @var string
+ * @ORM\Column(name="zipcode", type="string", length=255)
+ */
+ private $zipcode;
+
+
+ /**
+ * Get id
+ *
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * Set user
+ *
+ * @param integer $user
+ * @return Address
+ */
+ public function setUser($user)
+ {
+ $this->user = $user;
+
+ return $this;
+ }
+
+ /**
+ * Get user
+ *
+ * @return User
+ */
+ public function getUser()
+ {
+ return $this->user;
+ }
+
+ /**
+ * Set street
+ *
+ * @param string $street
+ * @return Address
+ */
+ public function setStreet($street)
+ {
+ $this->street = $street;
+
+ return $this;
+ }
+
+ /**
+ * Get street
+ *
+ * @return string
+ */
+ public function getStreet()
+ {
+ return $this->street;
+ }
+
+ /**
+ * Set city
+ *
+ * @param string $city
+ * @return Address
+ */
+ public function setCity($city)
+ {
+ $this->city = $city;
+
+ return $this;
+ }
+
+ /**
+ * Get city
+ *
+ * @return string
+ */
+ public function getCity()
+ {
+ return $this->city;
+ }
+
+ /**
+ * Set zipcode
+ *
+ * @param string $zipcode
+ * @return Address
+ */
+ public function setZipcode($zipcode)
+ {
+ $this->zipcode = $zipcode;
+
+ return $this;
+ }
+
+ /**
+ * Get zipcode
+ *
+ * @return string
+ */
+ public function getZipcode()
+ {
+ return $this->zipcode;
+ }
+
+}
+
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 5dd2213..333446e 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -14,119 +14,282 @@
*/
class User implements UserInterface
{
-
- /**
- * @var int
- * @ORM\Id
- * @ORM\GeneratedValue
- * @ORM\Column(type="integer")
- */
- private $id;
-
- /**
- * @ORM\Column(type="string", length=255, unique=true, name="email")
- * @Assert\NotBlank()
- * @Assert\Email()
- */
- private $username;
-
- /**
- * @ORM\Column(type="string", length=64)
- */
- private $password;
-
- /**
- * @Assert\NotBlank()
- * @Assert\Length(max=4096)
- */
- private $plainPassword;
-
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * @param int $id
- * @return self
- */
- public function setId($id)
- {
- $this->id = $id;
- return $this;
- }
-
- /**
- * @return mixed
- */
- public function getUsername()
- {
- return $this->username;
- }
-
- /**
- * @param mixed $username
- * @return self
- */
- public function setUsername($username)
- {
- $this->username = $username;
- return $this;
- }
-
- /**
- * @return mixed
- */
- public function getPassword()
- {
- return $this->password;
- }
-
- /**
- * @param mixed $password
- * @return self
- */
- public function setPassword($password)
- {
- $this->password = $password;
- return $this;
- }
-
- /**
- * @return mixed
- */
- public function getPlainPassword()
- {
- return $this->plainPassword;
- }
-
- /**
- * @param mixed $plainPassword
- * @return self
- */
- public function setPlainPassword($plainPassword)
- {
- $this->plainPassword = $plainPassword;
- return $this;
- }
-
- public function getRoles()
- {
- return [];
- }
-
- public function getSalt()
- {
- return null;
- }
-
- public function eraseCredentials()
- {
- //nothing to do
- return;
- }
-
+
+ /**
+ * @var int
+ * @ORM\Id
+ * @ORM\GeneratedValue
+ * @ORM\Column(type="integer")
+ */
+ private $id;
+
+ /**
+ * @ORM\Column(type="string", length=255, unique=true, name="email")
+ * @Assert\NotBlank()
+ * @Assert\Email()
+ */
+ private $username;
+
+ /**
+ * @ORM\Column(type="string", length=64)
+ */
+ private $password;
+
+ /**
+ * @ORM\Column(type="string", length=255, nullable=true, name="name")
+ */
+ private $name;
+
+ /**
+ * @ORM\Column(type="string", length=255, nullable=true, name="surname")
+ */
+ private $surname;
+
+ /**
+ * @ORM\Column(type="string", length=15, nullable=true, name="phone")
+ */
+ private $phone;
+
+ /**
+ * @var string
+ * @ORM\Column(name="street", type="string", nullable=true, length=255)
+ */
+ private $street;
+
+ /**
+ * @var string
+ * @ORM\Column(name="city", type="string", nullable=true, length=255)
+ */
+ private $city;
+
+ /**
+ * @var string
+ * @ORM\Column(name="zipcode", type="string", nullable=true, length=255)
+ */
+ private $zipcode;
+
+ /**
+ * @Assert\NotBlank()
+ * @Assert\Length(max=4096)
+ */
+ private $plainPassword;
+
+ /**
+ * @return int
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @param int $id
+ * @return self
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getUsername()
+ {
+ return $this->username;
+ }
+
+ /**
+ * @param mixed $username
+ * @return self
+ */
+ public function setUsername($username)
+ {
+ $this->username = $username;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getPhone()
+ {
+ return $this->phone;
+ }
+
+ /**
+ * @param mixed $phone
+ * @return self
+ */
+ public function setPhone($phone)
+ {
+ $this->phone = $phone;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getPassword()
+ {
+ return $this->password;
+ }
+
+ /**
+ * @param mixed $password
+ * @return self
+ */
+ public function setPassword($password)
+ {
+ $this->password = $password;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getPlainPassword()
+ {
+ return $this->plainPassword;
+ }
+
+ /**
+ * @param mixed $plainPassword
+ * @return self
+ */
+ public function setPlainPassword($plainPassword)
+ {
+ $this->plainPassword = $plainPassword;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * @param mixed $name
+ * @return self
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getSurname()
+ {
+ return $this->surname;
+ }
+
+ /**
+ * @param mixed $surname
+ * @return self
+ */
+ public function setSurname($surname)
+ {
+ $this->surname = $surname;
+
+ return $this;
+ }
+
+ /**
+ * Set street
+ *
+ * @param string $street
+ * @return Address
+ */
+ public function setStreet($street)
+ {
+ $this->street = $street;
+
+ return $this;
+ }
+
+ /**
+ * Get street
+ *
+ * @return string
+ */
+ public function getStreet()
+ {
+ return $this->street;
+ }
+
+ /**
+ * Set city
+ *
+ * @param string $city
+ * @return Address
+ */
+ public function setCity($city)
+ {
+ $this->city = $city;
+
+ return $this;
+ }
+
+ /**
+ * Get city
+ *
+ * @return string
+ */
+ public function getCity()
+ {
+ return $this->city;
+ }
+
+ /**
+ * Set zipcode
+ *
+ * @param string $zipcode
+ * @return Address
+ */
+ public function setZipcode($zipcode)
+ {
+ $this->zipcode = $zipcode;
+
+ return $this;
+ }
+
+ /**
+ * Get zipcode
+ *
+ * @return string
+ */
+ public function getZipcode()
+ {
+ return $this->zipcode;
+ }
+
+ public function getRoles()
+ {
+ return [];
+ }
+
+ public function getSalt()
+ {
+ return null;
+ }
+
+ public function eraseCredentials()
+ {
+ //nothing to do
+ return;
+ }
+
}
diff --git a/src/AppBundle/FormType/AddressFormType.php b/src/AppBundle/FormType/AddressFormType.php
new file mode 100644
index 0000000..ad1bc57
--- /dev/null
+++ b/src/AppBundle/FormType/AddressFormType.php
@@ -0,0 +1,49 @@
+
+ */
+class AddressFormType extends AbstractType
+{
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add("street", TextType::class, [
+ "label" => "Ulice",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("city", TextType::class, [
+ "label" => "Město",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("zipcode", TextType::class, [
+ "label" => "PSČ",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add('submit', SubmitType::class, [
+ 'label' => 'Uložit změny',
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+}
\ No newline at end of file
diff --git a/src/AppBundle/FormType/PasswordFormType.php b/src/AppBundle/FormType/PasswordFormType.php
new file mode 100644
index 0000000..901486c
--- /dev/null
+++ b/src/AppBundle/FormType/PasswordFormType.php
@@ -0,0 +1,47 @@
+
+ */
+class PasswordFormType extends AbstractType
+{
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add("plainPassword", RepeatedType::class, [
+ "type" => PasswordType::class,
+ "first_options" => [
+ "label" => "Nové heslo",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ],
+ "second_options" => [
+ "label" => "Zopakuj heslo",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ],
+ ])
+ ->add('submit', SubmitType::class, [
+ 'label' => 'Uložit změny',
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+}
\ No newline at end of file
diff --git a/src/AppBundle/FormType/UserFormType.php b/src/AppBundle/FormType/UserFormType.php
new file mode 100644
index 0000000..a71347a
--- /dev/null
+++ b/src/AppBundle/FormType/UserFormType.php
@@ -0,0 +1,50 @@
+
+ */
+class UserFormType extends AbstractType
+{
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add("name", TextType::class, [
+ "label" => "Jméno",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("surname", TextType::class, [
+ "label" => "Příjmení",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("phone", TextType::class, [
+ "label" => "Telefon",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add('submit', SubmitType::class, [
+ 'label' => 'Uložit změny',
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+}
\ No newline at end of file
diff --git a/src/AppBundle/Repository/AddressRepository.php b/src/AppBundle/Repository/AddressRepository.php
new file mode 100644
index 0000000..407c58f
--- /dev/null
+++ b/src/AppBundle/Repository/AddressRepository.php
@@ -0,0 +1,15 @@
+