- $this->addFlash('error', $this->translator->trans('Account %mail% already exists', ['%mail%' => $mail]));
-
- //Redirect to user view
- return $this->redirectToRoute($this->config['route']['edit']['name'], ['mail' => $smail]+$this->config['route']['edit']['context']);
- }
-
- //Get extra
- $extra = $slugger->unserialize($sextra = $extra);
-
- //Without valid extra
- if (!is_array($extra)) {
- //Throw bad request
- throw new BadRequestHttpException($this->translator->trans('Invalid %field% field: %value%', ['%field%' => 'extra', '%value%' => $sextra]));
- }
-
- //Extract names and pseudonym from mail
- $names = explode(' ', $pseudonym = ucwords(trim(preg_replace('/[^a-zA-Z]+/', ' ', current(explode('@', $mail))))));
-
- //Get manager
- $manager = $doctrine->getManager();
-
- //Init reflection
- $reflection = new \ReflectionClass($this->config['class']['user']);
-
- //Create new user
- $user = $reflection->newInstance();
-
- //Set mail
- $user->setMail($mail);
-
- //Set default value
- $default = [
- 'civility(title)' => $this->config['default']['civility'],
- 'pseudonym' => $pseudonym,
- 'forename' => $names[0]??$pseudonym,
- 'surname' => $names[1]??$pseudonym,
- 'password' => $encoder->encodePassword($user, $mail),
- 'active' => true
- ];
-
- //Iterate on each default value
- //TODO: store add/set action between [] ???
- foreach($extra+$default as $key => $value) {
- //Set member
- $member = $key;
-
- //With title entity
- if (substr($key, -strlen('(title)')) === '(title)') {
- //Remove field info
- $member = substr($member, 0, -strlen('(title)'));
-
- //Get object as value
- $value = $doctrine->getRepository($this->config['class'][$member])->findOneByTitle($value);
- //With id entity
- } elseif (substr($key, -strlen('(id)')) === '(id)') {
- //Remove field info
- $member = substr($member, 0, -strlen('(id)'));
-
- //Get object as value
- $value = $doctrine->getRepository($this->config['class'][$key])->findOneById($value);
- }
-
- //Set value
- $user->{'set'.ucfirst($member)}($value);