/** * Create new user * * @param $email * @param $name * @param $passwd * * @return array */ public function create(string $email, string $name, string $passwd, string $salt, string $locationName, array $latlng) : User { $entityManager = $this->getEntityManager(); $model = new User(); $model->setEmail($email)->setName($name)->setPasswd(Auth::createPassword($passwd, $salt))->setSalt($salt)->setApproved(false)->setCreated(new \DateTime("now"))->setLatlng($latlng)->setLocationName($locationName); $entityManager->persist($model); $this->getElastic()->persist($model); $hash = hash('sha1', time() . '|' . $model->getId()); $model->setUserhash($hash); $entityManager->persist($model); $entityManager->flush(); return $model; }
/** * @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); }