]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Controller/DefaultController.php
Switch to new getRecipientName user entity function
[userbundle] / Controller / DefaultController.php
index 7f6b02e0c755b2196a2b4a96bb42ff650c55067b..c431b5d8af1688ee6cf1230bd1b458477976d526 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'),
-                       //Disable slug
-                       'slug' => $this->isGranted('ROLE_ADMIN'),
                        //Disable password
                        'password' => false,
                        //Set method
                        'method' => 'POST'
-               ]);
+               ]+$this->config['edit']['field']);
 
                //With admin role
                if ($this->isGranted('ROLE_ADMIN')) {
@@ -202,21 +200,6 @@ class DefaultController extends AbstractController {
                                //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);
 
@@ -408,7 +391,7 @@ class DefaultController extends AbstractController {
                                                $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, '.', '%', '%');
@@ -650,7 +633,7 @@ class DefaultController extends AbstractController {
                                                $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, '.', '%', '%');
@@ -738,10 +721,7 @@ class DefaultController extends AbstractController {
                        $sfield = $field;
 
                        //Reset field
-                       $field = [
-                               //Without slug
-                               'slug' => false
-                       ];
+                       $field = [];
                }
 
                //Init reflection
@@ -762,7 +742,7 @@ class DefaultController extends AbstractController {
                        'mail' => true,
                        //Set method
                        'method' => 'POST'
-               ]);
+               ]+$this->config['register']['field']);
 
                if ($request->isMethod('POST')) {
                        //Refill the fields in case the form is not valid.
@@ -790,26 +770,8 @@ class DefaultController extends AbstractController {
                                //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
-                               $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);
@@ -849,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
-                               $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, '.', '%', '%');