diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig
index 7e93622..91af1ba 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
@@ -72,6 +72,14 @@
+ {% if app.session.flashBag.has('success') %}
+
+ {% for msg in app.session.flashBag.get('success') %}
+ {{ msg }}
+ {% endfor %}
+
+ {% endif %}
+
{% block body %}
{% 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..b8b2775
--- /dev/null
+++ b/app/Resources/views/user/profile.html.twig
@@ -0,0 +1,5 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+ {{ form(form) }}
+{% endblock %}
\ No newline at end of file
diff --git a/app/config/security.yml b/app/config/security.yml
index 82c6691..aea4294 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -9,6 +9,22 @@ security:
entity: { class: AppBundle:User, property: username }
firewalls:
+ user_area:
+ pattern: ^/profil
+
+ anonymous: false
+
+ 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
secured_area:
pattern: ^/
diff --git a/src/AppBundle/Controller/UserController.php b/src/AppBundle/Controller/UserController.php
index d0958e3..c1e06c9 100644
--- a/src/AppBundle/Controller/UserController.php
+++ b/src/AppBundle/Controller/UserController.php
@@ -3,12 +3,14 @@
use AppBundle\Entity\User;
use AppBundle\Facade\UserFacade;
use AppBundle\FormType\RegistrationFormType;
+use AppBundle\FormType\ProfileFormType;
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
@@ -97,6 +99,33 @@ public function loginAction()
public function logoutAction()
{}
+ /**
+ * @Route("/profil", name="user_profile")
+ * @Template("user/profile.html.twig")
+ *
+ * @param Request $request
+ * @return array
+ */
+ public function profileAction(Request $request)
+ {
+ $user = $this->userFacade->getUser();
+ $form = $this->formFactory->create(ProfileFormType::class, $user);
+
+ $form->handleRequest($request);
+ if ($form->isSubmitted() && $form->isValid()) {
+
+ $this->entityManager->persist($user);
+ $this->entityManager->flush();
+
+ $request->getSession()->getFlashBag()->add('success', 'Vaše údaje boli úspešne upravené');
+ }
+
+ return [
+ "form" => $form->createView(),
+ "user" => $this->userFacade->getUser(),
+ ];
+ }
+
/**
* @Route("/uzivatel/super-tajna-stranka", name="supersecret")
* @Template("user/supersecret.html.twig")
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 5dd2213..dd8b03f 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -41,6 +41,42 @@ class User implements UserInterface
*/
private $plainPassword;
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $name = '';
+
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $surname = '';
+
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $street = '';
+
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $city = '';
+
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $zip = '';
+
+ /**
+ * @var string
+ * @ORM\Column(type="string")
+ */
+ private $phone = '';
+
/**
* @return int
*/
@@ -129,4 +165,112 @@ public function eraseCredentials()
return;
}
+ /**
+ * @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;
+ }
+
+ /**
+ * @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->city;
+ }
+
+ /**
+ * @param mixed $city
+ * @return self
+ */
+ public function setCity($city)
+ {
+ $this->city = $city;
+ 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 getPhone()
+ {
+ return $this->phone;
+ }
+
+ /**
+ * @param mixed $phone
+ * @return self
+ */
+ public function setPhone($phone)
+ {
+ $this->phone = $phone;
+ return $this;
+ }
+
}
diff --git a/src/AppBundle/FormType/ProfileFormType.php b/src/AppBundle/FormType/ProfileFormType.php
new file mode 100644
index 0000000..c0dba1a
--- /dev/null
+++ b/src/AppBundle/FormType/ProfileFormType.php
@@ -0,0 +1,77 @@
+
+ */
+class ProfileFormType extends AbstractType
+{
+ public function buildForm(FormBuilderInterface $builder, array $options)
+ {
+ $builder
+ ->add("name", TextType::class, [
+ "label" => "Meno",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("surname", TextType::class, [
+ "label" => "Priezvisko",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("street", TextType::class, [
+ "label" => "Ulica",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("city", TextType::class, [
+ "label" => "Mesto",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("zip", TextType::class, [
+ "label" => "PSČ",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("phone", TextType::class, [
+ "label" => "Telefón",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("username", EmailType::class, [
+ "label" => "E-mail",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("submit", SubmitType::class, [
+ "label" => "Uložiť",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ]);
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ 'validation_groups' => ['edit'],
+ ));
+ }
+}
\ No newline at end of file