2012-07-01 08:02:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
|
2012-07-09 15:29:37 +00:00
|
|
|
use KekRozsak\FrontBundle\Form\Type\UserType;
|
|
|
|
|
2012-07-01 08:02:35 +00:00
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
2012-07-01 18:29:59 +00:00
|
|
|
public function homepageAction()
|
|
|
|
{
|
|
|
|
$mainPageArticle = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBy(array('main_page' => 1), true, array('created_at', 'DESC'), 1);
|
|
|
|
if (!$mainPageArticle)
|
|
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
|
|
|
|
return $this->forward('KekRozsakFrontBundle:Default:article', array('articleSlug' => $mainPageArticle->getSlug()));
|
|
|
|
}
|
|
|
|
|
2012-07-01 17:11:31 +00:00
|
|
|
public function articleAction($articleSlug)
|
|
|
|
{
|
|
|
|
$article = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBySlug($articleSlug);
|
|
|
|
|
2012-07-01 18:29:59 +00:00
|
|
|
if (!$article)
|
|
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
|
2012-07-01 17:11:31 +00:00
|
|
|
return $this->render('KekRozsakFrontBundle:Default:article.html.twig', array(
|
|
|
|
'article' => $article
|
|
|
|
));
|
|
|
|
}
|
2012-07-09 15:29:37 +00:00
|
|
|
|
|
|
|
public function profileEditAction()
|
|
|
|
{
|
|
|
|
$user = $this->get('security.context')->getToken()->getUser();
|
|
|
|
$oldPassword = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:User')->findOneById($user->getId())->getPassword();
|
|
|
|
$form = $this->createForm(new UserType(), $user);
|
|
|
|
|
|
|
|
$saveSuccess = false;
|
|
|
|
$request = $this->getRequest();
|
|
|
|
if ($request->getMethod() == 'POST')
|
|
|
|
{
|
|
|
|
$form->bindRequest($request);
|
|
|
|
if ($form->isValid())
|
|
|
|
{
|
|
|
|
if ($user->getPassword() != '')
|
|
|
|
{
|
|
|
|
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$user->setPassword($oldPassword);
|
|
|
|
}
|
|
|
|
if ($user->getUserData()->getUserId() === null)
|
|
|
|
{
|
|
|
|
$user->getUserData()->setUser($user);
|
|
|
|
}
|
|
|
|
$em = $this->getDoctrine()->getEntityManager();
|
|
|
|
$em->persist($user);
|
|
|
|
$em->flush();
|
|
|
|
// $saveSuccess = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('KekRozsakFrontBundle:Default:userprofile.html.twig', array(
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'saveSuccess' => $saveSuccess,
|
|
|
|
));
|
|
|
|
}
|
2012-07-01 08:02:35 +00:00
|
|
|
}
|