Added user profile editing support

This commit is contained in:
Polonkai Gergely
2012-07-09 17:29:37 +02:00
parent 0fad11ffd0
commit 8a55e32303
12 changed files with 775 additions and 24 deletions

View File

@@ -4,6 +4,8 @@ namespace KekRozsak\FrontBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use KekRozsak\FrontBundle\Form\Type\UserType;
class DefaultController extends Controller
{
public function homepageAction()
@@ -26,4 +28,42 @@ class DefaultController extends Controller
'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,
));
}
}