]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Controller/DefaultController.php
Replace logout success handler with default logout listener
[userbundle] / Controller / DefaultController.php
index c8bb8a54886c148196bef5ed69681740dba4914b..070df0cb553e60519ba4f6bbe973bcc9f1720917 100644 (file)
@@ -136,13 +136,11 @@ class DefaultController extends AbstractController {
                        'civility_default' => $doctrine->getRepository($this->config['class']['civility'])->findOneByTitle($this->config['default']['civility']),
                        //Disable mail
                        'mail' => $this->isGranted('ROLE_ADMIN'),
                        'civility_default' => $doctrine->getRepository($this->config['class']['civility'])->findOneByTitle($this->config['default']['civility']),
                        //Disable mail
                        'mail' => $this->isGranted('ROLE_ADMIN'),
-                       //Disable slug
-                       'slug' => $this->isGranted('ROLE_ADMIN'),
                        //Disable password
                        'password' => false,
                        //Set method
                        'method' => 'POST'
                        //Disable password
                        'password' => false,
                        //Set method
                        'method' => 'POST'
-               ]);
+               ]+$this->config['edit']['field']);
 
                //With admin role
                if ($this->isGranted('ROLE_ADMIN')) {
 
                //With admin role
                if ($this->isGranted('ROLE_ADMIN')) {
@@ -185,11 +183,6 @@ class DefaultController extends AbstractController {
 
                        //Add reset view
                        $this->config['edit']['view']['context']['reset'] = $reset->createView();
 
                        //Add reset view
                        $this->config['edit']['view']['context']['reset'] = $reset->createView();
-               //Without admin role
-               //XXX: prefer a reset on login to force user unspam action
-               } else {
-                       //Add notice
-                       $this->addFlash('notice', $this->translator->trans('To change your password login with your mail and any password then follow the procedure'));
                }
 
                //With post method
                }
 
                //With post method
@@ -202,21 +195,6 @@ class DefaultController extends AbstractController {
                                //Set data
                                $data = $edit->getData();
 
                                //Set data
                                $data = $edit->getData();
 
-                               //Set slug
-                               $slug = null;
-
-                               //With admin
-                               if ($this->isGranted('ROLE_ADMIN')) {
-                                       //With slug
-                                       if (!empty($data->getSlug())) {
-                                               //Set slug
-                                               $slug = $slugger->slug($data->getPseudonym());
-                                       }
-
-                                       //Update slug
-                                       $data->setSlug($slug);
-                               }
-
                                //Queue snippet save
                                $manager->persist($data);
 
                                //Queue snippet save
                                $manager->persist($data);
 
@@ -233,9 +211,14 @@ class DefaultController extends AbstractController {
                                //Catch double slug or mail
                                } catch (UniqueConstraintViolationException $e) {
                                        //Add error message mail already exists
                                //Catch double slug or mail
                                } catch (UniqueConstraintViolationException $e) {
                                        //Add error message mail already exists
-                                       $this->addFlash('error', $this->translator->trans('Account %mail% or with slug %slug% already exists', ['%mail%' => $data->getMail(), '%slug%' => $slug]));
+                                       $this->addFlash('error', $this->translator->trans('Account %mail% already exists', ['%mail%' => $data->getMail()]));
                                }
                        }
                                }
                        }
+               //Without admin role
+               //XXX: prefer a reset on login to force user unspam action
+               } elseif (!$this->isGranted('ROLE_ADMIN')) {
+                       //Add notice
+                       $this->addFlash('notice', $this->translator->trans('To change your password login with your mail and any password then follow the procedure'));
                }
 
                //Render view
                }
 
                //Render view
@@ -408,7 +391,7 @@ class DefaultController extends AbstractController {
                                                $recoverMail['context']['recipient_mail'] = $user->getMail();
 
                                                //Set recipient_name
                                                $recoverMail['context']['recipient_mail'] = $user->getMail();
 
                                                //Set recipient_name
-                                               $recoverMail['context']['recipient_name'] = trim($user->getForename().' '.$user->getSurname().($user->getPseudonym()?' ('.$user->getPseudonym().')':''));
+                                               $recoverMail['context']['recipient_name'] = $user->getRecipientName();
 
                                                //Init subject context
                                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['recover']['view']['context'], $recoverMail['context']), null, '.', '%', '%');
 
                                                //Init subject context
                                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['recover']['view']['context'], $recoverMail['context']), null, '.', '%', '%');
@@ -609,18 +592,21 @@ class DefaultController extends AbstractController {
                                        //With disabled existing
                                        if ($existing->isDisabled()) {
                                                //Render view
                                        //With disabled existing
                                        if ($existing->isDisabled()) {
                                                //Render view
-                                               return $this->render(
+                                               $response = $this->render(
                                                        //Template
                                                        $this->config['register']['view']['name'],
                                                        //Context
                                                        //Template
                                                        $this->config['register']['view']['name'],
                                                        //Context
-                                                       ['title' => $this->translator->trans('Access denied'), 'disabled' => 1]+$this->config['register']['view']['context'],
-                                                       //Set 403
-                                                       new Response('', 403)
+                                                       ['title' => $this->translator->trans('Access denied'), 'disabled' => 1]+$this->config['register']['view']['context']
                                                );
                                                );
+
+                                               //Set 403
+                                               $response->setStatusCode(403);
+
+                                               //Return response
+                                               return $response;
                                        //With unactivated existing
                                        } elseif (!$existing->isActivated()) {
                                                //Set mail shortcut
                                        //With unactivated existing
                                        } elseif (!$existing->isActivated()) {
                                                //Set mail shortcut
-                                               //TODO: change for activate ???
                                                $activateMail =& $this->config['register']['mail'];
 
                                                //Generate each route route
                                                $activateMail =& $this->config['register']['mail'];
 
                                                //Generate each route route
@@ -647,7 +633,7 @@ class DefaultController extends AbstractController {
                                                $activateMail['context']['recipient_mail'] = $existing->getMail();
 
                                                //Set recipient name
                                                $activateMail['context']['recipient_mail'] = $existing->getMail();
 
                                                //Set recipient name
-                                               $activateMail['context']['recipient_name'] = implode(' ', [$existing->getForename(), $existing->getSurname(), $existing->getPseudonym()?'('.$existing->getPseudonym().')':'']);
+                                               $activateMail['context']['recipient_name'] = $existing->getRecipientName();
 
                                                //Init subject context
                                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['register']['view']['context'], $activateMail['context']), null, '.', '%', '%');
 
                                                //Init subject context
                                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['register']['view']['context'], $activateMail['context']), null, '.', '%', '%');
@@ -735,10 +721,7 @@ class DefaultController extends AbstractController {
                        $sfield = $field;
 
                        //Reset field
                        $sfield = $field;
 
                        //Reset field
-                       $field = [
-                               //Without slug
-                               'slug' => false
-                       ];
+                       $field = [];
                }
 
                //Init reflection
                }
 
                //Init reflection
@@ -759,7 +742,7 @@ class DefaultController extends AbstractController {
                        'mail' => true,
                        //Set method
                        'method' => 'POST'
                        'mail' => true,
                        //Set method
                        'method' => 'POST'
-               ]);
+               ]+$this->config['register']['field']);
 
                if ($request->isMethod('POST')) {
                        //Refill the fields in case the form is not valid.
 
                if ($request->isMethod('POST')) {
                        //Refill the fields in case the form is not valid.
@@ -787,26 +770,8 @@ class DefaultController extends AbstractController {
                                //Set mail shortcut
                                $registerMail =& $this->config['register']['mail'];
 
                                //Set mail shortcut
                                $registerMail =& $this->config['register']['mail'];
 
-                               //Extract names and pseudonym from mail
-                               $names = explode(' ', $pseudonym = ucwords(trim(preg_replace('/[^a-zA-Z]+/', ' ', current(explode('@', $data->getMail()))))));
-
-                               //Set pseudonym
-                               $user->setPseudonym($user->getPseudonym()??$pseudonym);
-
-                               //Set forename
-                               $user->setForename($user->getForename()??$names[0]);
-
-                               //Set surname
-                               $user->setSurname($user->getSurname()??$names[1]??$names[0]);
-
                                //Set password
                                //Set password
-                               $user->setPassword($encoder->encodePassword($user, $user->getPassword()??$data->getMail()));
-
-                               //Set created
-                               $user->setCreated(new \DateTime('now'));
-
-                               //Set updated
-                               $user->setUpdated(new \DateTime('now'));
+                               $user->setPassword($encoder->encodePassword($user, $user->getPassword()));
 
                                //Persist user
                                $manager->persist($user);
 
                                //Persist user
                                $manager->persist($user);
@@ -846,17 +811,11 @@ class DefaultController extends AbstractController {
                                        }
                                }
 
                                        }
                                }
 
-                               //XXX: DEBUG: remove me
-                               //die($registerMail['context']['confirm_url']);
-
                                //Set recipient_name
                                $registerMail['context']['recipient_mail'] = $data->getMail();
 
                                //Set recipient name
                                //Set recipient_name
                                $registerMail['context']['recipient_mail'] = $data->getMail();
 
                                //Set recipient name
-                               $registerMail['context']['recipient_name'] = '';
-
-                               //Set recipient name
-                               $registerMail['context']['recipient_name'] = implode(' ', [$data->getForename(), $data->getSurname(), $data->getPseudonym()?'('.$data->getPseudonym().')':'']);
+                               $registerMail['context']['recipient_name'] = $data->getRecipientName();
 
                                //Init subject context
                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['register']['view']['context'], $registerMail['context']), null, '.', '%', '%');
 
                                //Init subject context
                                $subjectContext = $slugger->flatten(array_replace_recursive($this->config['register']['view']['context'], $registerMail['context']), null, '.', '%', '%');