Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ukol 3 - Jozef Liška #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/Resources/views/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</ul>
<p class="navbar-text navbar-right">
{% if user is defined and user %}
<a href="#" class="navbar-link">{{ user.username }}</a>
<a href="{{ path("user_profile") }}" class="navbar-link">{{ user.username }}</a>
| <a href="{{ path("user_logout") }}" class="navbar-link">Odhlásit</a>
{% else %}
<a href="{{ path("user_login") }}" class="navbar-link">Přihlásit</a>
Expand All @@ -72,6 +72,14 @@
</div>

<div class="col-md-9">
{% if app.session.flashBag.has('success') %}
<div class="alert alert-success">
{% for msg in app.session.flashBag.get('success') %}
{{ msg }}
{% endfor %}
</div>
{% endif %}

{% block body %}
{% endblock %}
</div>
Expand Down
5 changes: 5 additions & 0 deletions app/Resources/views/user/profile.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% extends 'base.html.twig' %}

{% block body %}
{{ form(form) }}
{% endblock %}
16 changes: 16 additions & 0 deletions app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ security:
entity: { class: AppBundle:User, property: username }

firewalls:
user_area:
pattern: ^/profil
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nerozumiem prečo, ale nefunguje mi to ako by malo. Ak sa aj prihlásim, tak ma po vstupe na /profil presmeruje na login page.


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: ^/

Expand Down
29 changes: 29 additions & 0 deletions src/AppBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
144 changes: 144 additions & 0 deletions src/AppBundle/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
}

}
77 changes: 77 additions & 0 deletions src/AppBundle/FormType/ProfileFormType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
namespace AppBundle\FormType;

use AppBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @author Jozef Liška <jozoliska@gmail.com>
*/
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'],
));
}
}