Added the possibility to register
This commit is contained in:
@@ -4,6 +4,10 @@ namespace KekRozsak\SecurityBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\Security\Core\SecurityContext;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use KekRozsak\FrontBundle\Entity\User;
|
||||
use KekRozsak\FrontBundle\Form\Type\UserType;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
@@ -27,4 +31,37 @@ class DefaultController extends Controller
|
||||
'error' => $error,
|
||||
));
|
||||
}
|
||||
|
||||
public function registrationAction(Request $request)
|
||||
{
|
||||
$user = new User();
|
||||
$form = $this->createForm(new UserType(true), $user);
|
||||
|
||||
if ($request->getMethod() == 'POST')
|
||||
{
|
||||
$form->bindRequest($request);
|
||||
if ($form->isValid(array('registration')))
|
||||
{
|
||||
$user->setPassword($this->get('security.encoder_factory')->getEncoder($user)->encodePassword($user->getPassword(), $user->getSalt()));
|
||||
$roleRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Role');
|
||||
$regRole = $roleRepo->findOneByName('ROLE_REGISTERED');
|
||||
$user->addRole($regRole);
|
||||
$user->setRegisteredAt(new \DateTime('now'));
|
||||
$em = $this->getDoctrine()->getEntityManager();
|
||||
$em->persist($user);
|
||||
$em->flush();
|
||||
|
||||
return $this->redirect($this->generateUrl('KekRozsakSecurityBundle_reg_success'));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('KekRozsakSecurityBundle:Default:registration.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
public function registrationSuccessAction()
|
||||
{
|
||||
return $this->render('KekRozsakSecurityBundle:Default:registration_success.html.twig', array());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user