Example #1
0
 /**
  * Logout user
  *
  * @param $hash
  */
 public function logout($hash)
 {
     /** @var User $model */
     $model = $this->authByHash($hash);
     $model->setUserhash(null);
     $this->getEntityManager()->flush();
     Auth::logout();
 }
Example #2
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;
 }
Example #3
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]);
 }
Example #4
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);
 }
Example #5
0
 /**
  * @param string $method
  *
  * @return mixed
  */
 public function beforeAction(string $method)
 {
     $methods = $this->guestAllowedMethods();
     $model = $this->getAuthService()->authByHash(Auth::getHash());
     if ($model === false && in_array($method, $methods, true)) {
         return true;
     }
     return $model;
 }
Example #6
0
 /**
  * Approve user
  *
  * @param $hash
  */
 public function approveAction(string $hash)
 {
     try {
         $model = $this->getAuthService()->authByHash($hash);
         if ($model) {
             $hash = hash('sha1', time() . '|' . $model->getId());
             $model->setUserhash($hash);
             $model->setApproved(true);
             $this->getEntityManager()->persist($model);
             $this->getEntityManager()->flush();
             Auth::setAuth($hash);
             $this->getEmailService()->sendSuccessEmail($model);
             $this->redirect('/');
         } else {
             echo 'Wrong hash given.';
         }
     } catch (\Exception $e) {
         echo 'Wrong hash given.';
     }
 }