diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig
index 7e93622..b59550f 100644
--- a/app/Resources/views/base.html.twig
+++ b/app/Resources/views/base.html.twig
@@ -44,8 +44,12 @@
{% if user is defined and user %}
diff --git a/app/Resources/views/user/supersecret.html.twig b/app/Resources/views/user/supersecret.html.twig
index 6c46670..a04ae8b 100644
--- a/app/Resources/views/user/supersecret.html.twig
+++ b/app/Resources/views/user/supersecret.html.twig
@@ -1,5 +1,20 @@
{% extends 'base.html.twig' %}
{% block body %}
- Hello {{ user.username }}
+ Hello {{ user.username }}
+
+ {{ form_start(form) }}
+ {{ form_row(form.username) }}
+ {{ form_row(form.phone) }}
+
+ {{ form_row(form.title) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.street) }}
+ {{ form_row(form.city) }}
+ {{ form_row(form.country) }}
+ {{ form_row(form.zip) }}
+
+
+ {{ form_end(form) }}
+
{% endblock %}
\ No newline at end of file
diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php
index d0958e3..fab7b72 100644
--- a/src/AppBundle/Controller/UserController.php
+++ b/src/AppBundle/Controller/UserController.php
@@ -1,8 +1,11 @@
* @author Jan Klat
* @Route(service="app.controller.user_controller")
*/
-class UserController
-{
- private $userFacade;
- private $formFactory;
- private $passwordEncoder;
- private $entityManager;
- private $router;
-
- public function __construct(
- UserFacade $userFacade,
- FormFactory $formFactory,
- PasswordEncoderInterface $passwordEncoder,
- EntityManager $entityManager,
- RouterInterface $router
- ) {
- $this->userFacade = $userFacade;
- $this->formFactory = $formFactory;
- $this->passwordEncoder = $passwordEncoder;
- $this->entityManager = $entityManager;
- $this->router = $router;
- }
-
- /**
- * @Route("/registrovat", name="user_registration")
- * @Template("user/registration.html.twig")
- *
- * @param Request $request
- * @return RedirectResponse|array
- */
- public function registrationAction(Request $request)
- {
- // 1) build the form
- $user = new User();
- $form = $this->formFactory->create(RegistrationFormType::class, $user);
-
- // 2) handle the submit (will only happen on POST)
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
-
- // 3) Encode the password (you could also do this via Doctrine listener)
- $user->setPassword(
- $this->passwordEncoder->encodePassword($user->getPlainPassword(), null)
- );
-
- // 4) save the User!
- $this->entityManager->persist($user);
- $this->entityManager->flush();
-
- // ... 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 [
- "form" => $form->createView(),
- ];
- }
-
- /**
- * @Route("/prihlasit", name="user_login")
- * @Template("user/login.html.twig")
- *
- * @return RedirectResponse|array
- */
- public function loginAction()
- {
- return [
- "last_username" => $this->userFacade->getLastUsername(),
- "error" => $this->userFacade->getAuthenticationError(),
- ];
- }
-
- /**
- * @Route("/odhlasit", name="user_logout")
- */
- public function logoutAction()
- {}
-
- /**
- * @Route("/uzivatel/super-tajna-stranka", name="supersecret")
- * @Template("user/supersecret.html.twig")
- *
- * @return array
- */
- public function superSecretAction()
- {
- if (!$this->userFacade->getUser()) {
- throw new UnauthorizedHttpException("Přihlašte se");
- }
- return [
- "user" => $this->userFacade->getUser(),
- ];
- }
-
-}
\ No newline at end of file
+class UserController {
+
+ private $userFacade;
+ private $formFactory;
+ private $passwordEncoder;
+ private $entityManager;
+ private $router;
+
+ public function __construct(
+ UserFacade $userFacade, FormFactory $formFactory, PasswordEncoderInterface $passwordEncoder, EntityManager $entityManager, RouterInterface $router
+ ) {
+ $this->userFacade = $userFacade;
+ $this->formFactory = $formFactory;
+ $this->passwordEncoder = $passwordEncoder;
+ $this->entityManager = $entityManager;
+ $this->router = $router;
+ }
+
+ /**
+ * @Route("/registrovat", name="user_registration")
+ * @Template("user/registration.html.twig")
+ *
+ * @param Request $request
+ * @return RedirectResponse|array
+ */
+ public function registrationAction(Request $request) {
+ // 1) build the form
+ $user = new User();
+ $form = $this->formFactory->create(RegistrationFormType::class, $user);
+
+ // 2) handle the submit (will only happen on POST)
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+
+ // 3) Encode the password (you could also do this via Doctrine listener)
+ $user->setPassword(
+ $this->passwordEncoder->encodePassword($user->getPlainPassword(), null)
+ );
+
+ // 4) save the User!
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ // ... 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 [
+ "form" => $form->createView(),
+ ];
+ }
+
+ /**
+ * @Route("/prihlasit", name="user_login")
+ * @Template("user/login.html.twig")
+ *
+ * @return RedirectResponse|array
+ */
+ public function loginAction() {
+ return [
+ "last_username" => $this->userFacade->getLastUsername(),
+ "error" => $this->userFacade->getAuthenticationError(),
+ ];
+ }
+
+ /**
+ * @Route("/odhlasit", name="user_logout")
+ */
+ public function logoutAction() {
+
+ }
+
+ /**
+ * @Route("/uzivatel/super-tajna-stranka", name="supersecret")
+ * @Template("user/supersecret.html.twig")
+ * @param Request $request
+ * @return array
+ */
+ public function superSecretAction(Request $request) {
+ if (!$this->userFacade->getUser()) {
+ throw new UnauthorizedHttpException("Přihlašte se");
+ }
+
+ // 1) build the form
+ $user = $this->userFacade->getUser();
+ $form = $this->formFactory->create(UserEditFormType::class, $user);
+
+ $user->setPlainPassword($user->getPassword());
+ // 2) handle the submit (will only happen on POST)
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+
+
+ // 4) save the User!
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ // ... 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 [
+ "form" => $form->createView(),
+ "user" => $this->userFacade->getUser(),
+ ];
+ }
+
+}
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 5dd2213..8229ff4 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -1,132 +1,280 @@
* @author Jan Klat
+ * @author Aleš Kůdela
* @ORM\Entity
* @UniqueEntity(fields="username", message="Tento e-mail je již registrován")
*/
-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;
- }
+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;
+
+ /**
+ * @ORM\Column(type="string", length=128, nullable=true)
+ */
+ private $phone;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=64)
+ */
+ private $title;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=64)
+ */
+ private $name;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255)
+ */
+ private $city;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255)
+ */
+ private $street;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=16)
+ */
+ private $zip;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255)
+ */
+ private $country;
+
+ public function __construct() {
+ $this->userAddresses = new ArrayCollection;
+ }
+
+ /**
+ * @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 getTitle() {
+ return $this->title;
+ }
+
+ /**
+ * @param mixed $title
+ * @return self
+ */
+ public function setTitle($title) {
+ $this->title = $title;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getName() {
+ return $this->title;
+ }
+
+ /**
+ * @param mixed $name
+ * @return self
+ */
+ public function setName($name) {
+ $this->name = $name;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getZip() {
+ return $this->zip;
+ }
+
+ /**
+ * @param mixed $zip
+ * @return self
+ */
+ public function setZip($zip) {
+ $this->zip = $zip;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getStreet() {
+ return $this->street;
+ }
+
+ /**
+ * @param mixed $street
+ * @return self
+ */
+ public function setStreet($street) {
+ $this->street = $street;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCity() {
+ return $this->street;
+ }
+
+ /**
+ * @param mixed $city
+ * @return self
+ */
+ public function setCity($city) {
+ $this->city = $city;
+ return $this;
+ }
+
+ /**
+ * @return mixed
+ */
+ public function getCountry() {
+ return $this->country;
+ }
+
+ /**
+ * @param mixed $country
+ * @return self
+ */
+ public function setCountry($country) {
+ $this->country = $country;
+ 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;
+ }
}
diff --git a/src/AppBundle/FormType/UserEditFormType.php b/src/AppBundle/FormType/UserEditFormType.php
new file mode 100644
index 0000000..466d049
--- /dev/null
+++ b/src/AppBundle/FormType/UserEditFormType.php
@@ -0,0 +1,76 @@
+add("username", EmailType::class, [
+ "label" => "E-mail",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("phone", TextType::class, [
+ "label" => "Telefon",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("title", TextType::class, [
+ "label" => "Pojmenování adresy",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("name", TextType::class, [
+ "label" => "Jméno adresáta",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->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",
+ ],
+ ])
+ ->add("country", TextType::class, [
+ "label" => "Stát",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver) {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+
+}