2012-07-01 08:02:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2012-07-15 12:56:31 +00:00
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
2012-07-01 08:02:35 +00:00
|
|
|
|
2012-07-31 07:46:25 +00:00
|
|
|
use KekRozsak\FrontBundle\Entity\Article;
|
2012-07-16 12:16:10 +00:00
|
|
|
|
2012-07-15 12:56:31 +00:00
|
|
|
use KekRozsak\SecurityBundle\Form\Type\UserType;
|
2012-07-09 15:29:37 +00:00
|
|
|
|
2012-07-01 08:02:35 +00:00
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* @Route("/", name="KekRozsakFrontBundle_homepage")
|
|
|
|
*/
|
|
|
|
public function homepageAction()
|
|
|
|
{
|
|
|
|
$mainPageArticle = $this
|
|
|
|
->getDoctrine()
|
|
|
|
->getRepository('KekRozsakFrontBundle:Article')
|
|
|
|
->findOneBy(
|
|
|
|
array('mainPage' => true),
|
|
|
|
true,
|
|
|
|
array('createdAt', 'DESC'),
|
|
|
|
1
|
|
|
|
);
|
|
|
|
if (!$mainPageArticle) {
|
|
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
}
|
2012-07-01 18:29:59 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return $this->forward('KekRozsakFrontBundle:Article:view', array('slug' => $mainPageArticle->getSlug()));
|
|
|
|
}
|
2012-07-09 15:29:37 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
/**
|
|
|
|
* @Route("/profil", name="KekRozsakFrontBundle_profile_edit")
|
|
|
|
* @Template("KekRozsakFrontBundle:Default:userprofile.html.twig")
|
|
|
|
*/
|
|
|
|
public function profileEditAction()
|
|
|
|
{
|
|
|
|
$user = $this->get('security.context')->getToken()->getUser();
|
2012-07-09 15:29:37 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
$oldPassword = $user->getPassword();
|
|
|
|
$form = $this->createForm(new UserType(), $user);
|
|
|
|
$saveSuccess = false;
|
|
|
|
$request = $this->getRequest();
|
2012-07-15 12:56:31 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
if ($request->getMethod() == 'POST') {
|
|
|
|
$form->bind($request);
|
|
|
|
if ($form->isValid()) {
|
|
|
|
if ($user->getPassword() == '') {
|
|
|
|
$user->setPassword($oldPassword);
|
|
|
|
} else {
|
|
|
|
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
|
|
|
|
}
|
2012-07-15 12:56:31 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($user);
|
|
|
|
$em->flush();
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 15:29:37 +00:00
|
|
|
|
2012-08-16 13:52:41 +00:00
|
|
|
return array(
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'saveSuccess' => $saveSuccess,
|
|
|
|
);
|
|
|
|
}
|
2012-07-01 08:02:35 +00:00
|
|
|
}
|