/** * Render signup form */ public function signupAction() { $autocomplete = $this->getMapService()->getAutocomplete(); if ($this->getRequest()->getMethod() === 'POST') { $params = $this->getRequest()->getBodyParams(); $name = $params['name']; $email = $params['email']; $locationName = $params['locationName']; $lat = $params['location']['lat']; $lng = $params['location']['lng']; try { $salt = Auth::generateSalt(); $passwd = Auth::generatePassword(); $user = $this->getUserService()->create($email, $name, $passwd, $salt, $locationName, [$lat, $lng]); $this->getEmailService()->sendConfirmationEmail($user, $passwd); return $this->redirect('/auth/login?newuser=true'); } catch (\Exception $e) { $map = $this->getMapService()->createEmptyMap(new Coordinate($lat, $lng)); $mapRender = $this->getMapService()->renderMap($map); return $this->render('/auth/signup', ['errors' => [$e->getMessage()], 'data' => ['name' => $name, 'email' => $email, 'locationName' => $locationName, 'lat' => $lat, 'lng' => $lng], 'location' => ['map' => trim($mapRender['html']), 'html' => trim($autocomplete['html']), 'js' => trim($autocomplete['js']) . trim($mapRender['js'])]]); } } $map = $this->getMapService()->createEmptyMap(new Coordinate()); $mapRender = $this->getMapService()->renderMap($map); return $this->render('/auth/signup', ['location' => ['map' => trim($mapRender['html']), 'html' => trim($autocomplete['html']), 'js' => trim($autocomplete['js']) . trim($mapRender['js'])]]); }
/** * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $email = ''; $name = ''; $helper = $this->getHelper('question'); $fields = ['email', 'name']; foreach ($fields as $field) { ${$field} = $input->getArgument($field); if (!${$field}) { $question = new Question(ucfirst($field) . ':', false); ${$field} = $helper->ask($input, $output, $question); } } $password = Auth::generatePassword(); $salt = Auth::generateSalt(); $output->writeln('Your password: '******'em')->getEntityManager(); $model = new User(); $model->setEmail($email)->setName($name)->setPasswd(Auth::createPassword($password, $salt))->setApproved(1)->setCreated(new \DateTime('now'))->setSalt($salt)->setLatlng([56, 30])->setLocationName('Saint-P'); $em->persist($model); $em->flush(); $this->elastic->persist($model); }