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..fc5bfa8
--- /dev/null
+++ b/app/Resources/views/user/profile.html.twig
@@ -0,0 +1,14 @@
+{% extends 'base.html.twig' %}
+
+{% block body %}
+ {{ form_start(form) }}
+ {{ form_row(form.name) }}
+ {{ form_row(form.street) }}
+ {{ form_row(form.city) }}
+ {{ form_row(form.psc) }}
+ {{ form_row(form.username) }}
+ {{ form_row(form.phone) }}
+
+
+ {{ 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..9492772 100644
--- a/src/AppBundle/Controller/UserController.php
+++ b/src/AppBundle/Controller/UserController.php
@@ -3,7 +3,7 @@
use AppBundle\Entity\User;
use AppBundle\Facade\UserFacade;
use AppBundle\FormType\RegistrationFormType;
-use Doctrine\ORM\EntityManager;
+use AppBundle\FormType\UserEditFormType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormFactory;
@@ -11,7 +11,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\Routing\RouterInterface;
-use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
+use AppBundle\Service\UserService;
/**
@@ -22,23 +22,20 @@
class UserController
{
private $userFacade;
- private $formFactory;
- private $passwordEncoder;
- private $entityManager;
+ private $formFactory;
private $router;
+ private $userService;
public function __construct(
UserFacade $userFacade,
- FormFactory $formFactory,
- PasswordEncoderInterface $passwordEncoder,
- EntityManager $entityManager,
- RouterInterface $router
+ FormFactory $formFactory,
+ RouterInterface $router,
+ UserService $userService
) {
$this->userFacade = $userFacade;
- $this->formFactory = $formFactory;
- $this->passwordEncoder = $passwordEncoder;
- $this->entityManager = $entityManager;
+ $this->formFactory = $formFactory;
$this->router = $router;
+ $this->userService = $userService;
}
/**
@@ -56,19 +53,8 @@ public function registrationAction(Request $request)
// 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
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->userService->registerUser($user);
return RedirectResponse::create($this->router->generate("homepage"));
}
@@ -90,6 +76,28 @@ public function loginAction()
"error" => $this->userFacade->getAuthenticationError(),
];
}
+
+ /**
+ * @Route("/profil", name="user_profile")
+ * @Template("user/profile.html.twig")
+ */
+ public function profileAction(Request $request){
+
+ $user = $this->userFacade->getUser();
+ $form = $this->formFactory->create(UserEditFormType::class, $user);
+
+ $form->handleRequest($request);
+
+ if ($form->isSubmitted() && $form->isValid()) {
+ $this->userService->saveUser($user);
+ return RedirectResponse::create($this->router->generate("homepage"));
+ }
+
+ return [
+ "form" => $form->createView(),
+ "user" => $this->userFacade->getUser(),
+ ];
+ }
/**
* @Route("/odhlasit", name="user_logout")
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
index 5dd2213..905f038 100644
--- a/src/AppBundle/Entity/User.php
+++ b/src/AppBundle/Entity/User.php
@@ -35,12 +35,41 @@ class User implements UserInterface
*/
private $password;
- /**
- * @Assert\NotBlank()
+ /**
* @Assert\Length(max=4096)
*/
private $plainPassword;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255, nullable=true)
+ */
+ private $name;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255, nullable=true)
+ */
+ private $street;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=255, nullable=true)
+ */
+ private $city;
+
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=64, nullable=true)
+ */
+ private $phone;
+ /**
+ * @var string
+ * @ORM\Column(type="string", length=6, nullable=true)
+ */
+ private $psc;
+
/**
* @return int
*/
@@ -129,4 +158,124 @@ public function eraseCredentials()
return;
}
+
+ /**
+ * Set name
+ *
+ * @param string $name
+ *
+ * @return User
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ /**
+ * Get name
+ *
+ * @return string
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Set street
+ *
+ * @param string $street
+ *
+ * @return User
+ */
+ 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 User
+ */
+ public function setCity($city)
+ {
+ $this->city = $city;
+
+ return $this;
+ }
+
+ /**
+ * Get city
+ *
+ * @return string
+ */
+ public function getCity()
+ {
+ return $this->city;
+ }
+
+ /**
+ * Set phone
+ *
+ * @param string $phone
+ *
+ * @return User
+ */
+ public function setPhone($phone)
+ {
+ $this->phone = $phone;
+
+ return $this;
+ }
+
+ /**
+ * Get phone
+ *
+ * @return string
+ */
+ public function getPhone()
+ {
+ return $this->phone;
+ }
+
+ /**
+ * Set psc
+ *
+ * @param string $psc
+ *
+ * @return User
+ */
+ public function setPsc($psc)
+ {
+ $this->psc = $psc;
+
+ return $this;
+ }
+
+ /**
+ * Get psc
+ *
+ * @return string
+ */
+ public function getPsc()
+ {
+ return $this->psc;
+ }
}
diff --git a/src/AppBundle/FormType/UserEditFormType.php b/src/AppBundle/FormType/UserEditFormType.php
new file mode 100644
index 0000000..ee9facc
--- /dev/null
+++ b/src/AppBundle/FormType/UserEditFormType.php
@@ -0,0 +1,61 @@
+add("name", TextType::class, [
+ "label" => "Jméno",
+ "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("psc", TextType::class, [
+ "label" => "PSČ",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("phone", TextType::class, [
+ "label" => "Telefon",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ->add("username", EmailType::class, [
+ "label" => "Email",
+ "attr" => [
+ "class" => "form-control",
+ ],
+ ])
+ ;
+ }
+
+ public function configureOptions(OptionsResolver $resolver)
+ {
+ $resolver->setDefaults(array(
+ "data_class" => User::class,
+ ));
+ }
+}
\ No newline at end of file
diff --git a/src/AppBundle/Service/UserService.php b/src/AppBundle/Service/UserService.php
new file mode 100644
index 0000000..04d1b81
--- /dev/null
+++ b/src/AppBundle/Service/UserService.php
@@ -0,0 +1,41 @@
+
+ * @author Jan Klat