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 - Milan Staněk #32

Open
wants to merge 1 commit 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
2 changes: 1 addition & 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 Down
23 changes: 23 additions & 0 deletions app/Resources/views/user/address.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends 'base.html.twig' %}

{% block body %}

<ul class="nav nav-tabs">
<li role="presentation"><a href="{{ path("user_profile") }}">Detail</a></li>
<li role="presentation"><a href="{{ path("user_password") }}">Heslo</a></li>
<li role="presentation" class="active"><a href="{{ path("user_address") }}">Adresa</a></li>
</ul>
<br />

{{ form_errors(form) }}

{{ form_start(form) }}
{{ form_row(form.street) }}
{{ form_row(form.city) }}
{{ form_row(form.zipcode) }}
<br />
{{ form_row(form.submit) }}
{{ form_end(form) }}

{% endblock %}

20 changes: 20 additions & 0 deletions app/Resources/views/user/password.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends 'base.html.twig' %}

{% block body %}

<ul class="nav nav-tabs">
<li role="presentation"><a href="{{ path("user_profile") }}">Detail</a></li>
<li role="presentation" class="active"><a href="{{ path("user_password") }}">Heslo</a></li>
<li role="presentation"><a href="{{ path("user_address") }}">Adresa</a></li>
</ul>
<br />

{{ form_start(form) }}
{{ form_row(form.plainPassword.first) }}
{{ form_row(form.plainPassword.second) }}
<br />
{{ form_row(form.submit) }}
{{ form_end(form) }}

{% endblock %}

23 changes: 23 additions & 0 deletions app/Resources/views/user/profile.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends 'base.html.twig' %}

{% block body %}

<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="{{ path("user_profile") }}">Detail</a></li>
<li role="presentation"><a href="{{ path("user_password") }}">Heslo</a></li>
<li role="presentation"><a href="{{ path("user_address") }}">Adresa</a></li>
</ul>
<br />

{{ form_errors(form) }}

{{ form_start(form) }}
{{ form_row(form.name) }}
{{ form_row(form.surname) }}
{{ form_row(form.phone) }}
<br />
{{ form_row(form.submit) }}
{{ form_end(form) }}

{% endblock %}

108 changes: 105 additions & 3 deletions src/AppBundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,13 +31,13 @@ class UserController
private $router;

public function __construct(
UserFacade $userFacade,
UserFacade $userFacade,
Copy link
Member

Choose a reason for hiding this comment

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

tady bacha na indenty (i :40)

FormFactory $formFactory,
PasswordEncoderInterface $passwordEncoder,
EntityManager $entityManager,
RouterInterface $router
) {
$this->userFacade = $userFacade;
$this->userFacade = $userFacade;
$this->formFactory = $formFactory;
$this->passwordEncoder = $passwordEncoder;
$this->entityManager = $entityManager;
Expand Down Expand Up @@ -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()) {
Copy link
Member

Choose a reason for hiding this comment

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

&& isValid


$this->entityManager->persist($user);
Copy link
Member

Choose a reason for hiding this comment

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

Do facade/repository s tím :)

$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,
];
}


}
151 changes: 151 additions & 0 deletions src/AppBundle/Entity/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Address
* @author Milan Stanek <mistacms@gmail.com>
* @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;
}

}

Loading