70 lines
2.0 KiB
PHP
70 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace KekRozsak\FrontBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use KekRozsak\FrontBundle\Form\Type\UserType;
|
|
|
|
class DefaultController extends Controller
|
|
{
|
|
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()));
|
|
}
|
|
|
|
public function articleAction($articleSlug)
|
|
{
|
|
$article = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Article')->findOneBySlug($articleSlug);
|
|
|
|
if (!$article)
|
|
throw $this->createNotFoundException('A keresett cikk nem létezik!');
|
|
|
|
return $this->render('KekRozsakFrontBundle:Default:article.html.twig', array(
|
|
'article' => $article
|
|
));
|
|
}
|
|
|
|
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,
|
|
));
|
|
}
|
|
}
|