kekrozsak/src/KekRozsak/SecurityBundle/Controller/DefaultController.php

120 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace KekRozsak\SecurityBundle\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;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\User\UserInterface;
2012-07-07 09:13:13 +00:00
2012-07-15 12:56:31 +00:00
use KekRozsak\SecurityBundle\Entity\User;
use KekRozsak\SecurityBundle\Form\Type\UserType;
use KekRozsak\FrontBundle\Entity\UserData;
class DefaultController extends Controller
{
/**
* @Route("/login", name="KekRozsakSecurityBundle_login")
2012-07-15 12:56:31 +00:00
* @Template()
*/
public function loginAction()
{
$request = $this->getRequest();
$session = $request->getSession();
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
{
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
}
else
{
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
2012-07-15 12:56:31 +00:00
return array(
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
2012-07-15 12:56:31 +00:00
);
}
2012-07-07 09:13:13 +00:00
/**
* @Route("/login_check", name="KekRozsakSecurityBundle_login_check")
*/
public function loginCheckAction()
{
// The security layer will intercept this request. This method will never be called.
}
/**
* @Route("/logout", name="KekRozsakSecurityBundle_logout")
*/
2012-07-15 12:56:31 +00:00
public function logoutAction()
{
// The security layer will intercept this request. This method will never be called.
2012-07-15 12:56:31 +00:00
}
/**
* @Route("/jelentkezes", name="KekRozsakSecurityBundle_registration")
2012-07-15 12:56:31 +00:00
* @Template()
*/
2012-07-15 12:56:31 +00:00
public function registrationAction()
2012-07-07 09:13:13 +00:00
{
$user = $this->get('security.context')->getToken()->getUser();
if ($user instanceof UserInterface)
{
return $this->redirect($this->generateUrl('KekRozsakFrontBundle_homepage'));
}
2012-07-15 12:56:31 +00:00
2012-07-07 09:13:13 +00:00
$user = new User();
$form = $this->createForm(new UserType(true), $user);
2012-07-15 12:56:31 +00:00
$request = $this->getRequest();
2012-07-07 09:13:13 +00:00
if ($request->getMethod() == 'POST')
{
$form->bindRequest($request);
2012-07-15 12:56:31 +00:00
2012-07-07 09:13:13 +00:00
if ($form->isValid(array('registration')))
{
$user->setRegisteredAt(new \DateTime('now'));
2012-07-15 12:56:31 +00:00
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
2012-07-07 09:13:13 +00:00
$em = $this->getDoctrine()->getEntityManager();
$em->persist($user);
$em->flush();
2012-07-15 12:56:31 +00:00
$userData = new UserData();
$user->setUserData($userData);
$em->persist($user);
$em->persist($userData);
$em->flush();
2012-07-07 20:15:36 +00:00
$message = \Swift_Message::newInstance()
->setSubject('Új jelentkező')
// TODO: Make this a config parameter!
2012-07-07 20:15:36 +00:00
->setFrom('info@blueroses.hu')
// TODO: Make this a config parameter!
->setTo('jelentkezes@blueroses.hu')
2012-07-07 20:15:36 +00:00
->setBody($this->renderView('KekRozsakSecurityBundle:Email:new_registration.txt.twig', array('user' => $user)));
$this->get('mailer')->send($message);
2012-07-07 09:13:13 +00:00
return $this->redirect($this->generateUrl('KekRozsakSecurityBundle_reg_success'));
}
}
2012-07-15 12:56:31 +00:00
return array(
2012-07-07 09:13:13 +00:00
'form' => $form->createView(),
2012-07-15 12:56:31 +00:00
);
2012-07-07 09:13:13 +00:00
}
/**
2012-07-15 12:56:31 +00:00
* @Route("/most_varj", name="KekRozsakSecurityBundle_reg_success")
* @Template()
*/
2012-07-15 12:56:31 +00:00
public function regSuccessAction()
2012-07-07 09:13:13 +00:00
{
2012-07-15 12:56:31 +00:00
return array(
);
2012-07-07 09:13:13 +00:00
}
}