Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Update user
  *
  * @param $id
  */
 public function updateAction(int $id)
 {
     $params = $this->getRequest()->getBodyParams();
     $name = $params['name'];
     $email = $params['email'];
     $spassword = $params['password'];
     $newPassword = $params['newpassword'];
     $rnewPassword = $params['rnewpassword'];
     $locationName = $params['locationName'];
     $location = [$params['lat'], $params['lng']];
     try {
         $model = $this->getUserService()->get($id);
         $password = '';
         if ($newPassword === $rnewPassword && Auth::createPassword($spassword, $model->getSalt()) === $model->getPasswd()) {
             $password = Auth::createPassword($newPassword, $model->getSalt());
         }
         $model = $this->getUserService()->update($model->getId(), $name, $email, $password, $locationName, $location);
     } catch (\InvalidArgumentException $e) {
         return $this->sendErrorResponse([$e->getMessage()]);
     }
     $this->sendResponse(['code' => 200]);
 }
Ejemplo n.º 3
0
 /**
  * @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);
 }