/** * @param UserInterface $user */ public function addSecretQuestion(UserInterface $user) { if (!$this->collectionOptions->getPasswordOptions()->isSecretQuestion()) { return; } $this->setUser($user); /** @var \PServerCore\Entity\Repository\SecretAnswer $repositorySecretAnswer */ $repositorySecretAnswer = $this->entityManager->getRepository($this->collectionOptions->getEntityOptions()->getSecretAnswer()); $answer = $repositorySecretAnswer->getAnswer4UserId($this->getUser()->getId()); if (!$answer) { return; } $this->add(['name' => 'question', 'options' => ['label' => 'SecretQuestion'], 'attributes' => ['placeholder' => 'Question', 'class' => 'form-control', 'type' => 'text', 'disabled' => 'true', 'value' => $answer->getQuestion()->getQuestion(), 'required' => true]]); $this->add(['name' => 'answer', 'options' => ['label' => 'SecretAnswer'], 'attributes' => ['placeholder' => 'Answer', 'class' => 'form-control', 'type' => 'text', 'required' => true]]); }
/** * @param Entity[] $codeList * * @return int */ protected function cleanExpireCodes4List(array $codeList) { $i = 0; $entityManager = $this->entityManager; foreach ($codeList as $code) { try { $entityManager->remove($code); // if we have a register-code, so we have to remove the user too if ($code->getType() == $code::TYPE_REGISTER) { $user = $code->getUser(); /** @var \PServerCore\Entity\Repository\Logs $logRepository */ $logRepository = $entityManager->getRepository($this->collectionOptions->getEntityOptions()->getLogs()); $logRepository->setLogsNull4User($user); /** @var \PServerCore\Entity\Repository\UserExtension $extensionRepository */ $extensionRepository = $entityManager->getRepository($this->collectionOptions->getEntityOptions()->getUserExtension()); $extensionRepository->deleteExtension($user); // secret question if ($this->collectionOptions->getPasswordOptions()->isSecretQuestion()) { /** @var \PServerCore\Entity\Repository\SecretAnswer $answerRepository */ $answerRepository = $entityManager->getRepository($this->collectionOptions->getEntityOptions()->getSecretAnswer()); $answerRepository->deleteAnswer4User($user); } $entityManager->remove($user); } $entityManager->flush(); ++$i; } catch (\Exception $exception) { // skip this exception } } return $i; }
/** * RegisterFilter constructor. * @param Collection $collection * @param EntityManager $entityManager * @param DataServiceInterface $gameBackendService */ public function __construct(Collection $collection, EntityManager $entityManager, DataServiceInterface $gameBackendService) { $this->collection = $collection; $this->entityManager = $entityManager; $this->gameBackendService = $gameBackendService; $validationUsernameOptions = $this->collection->getValidationOptions()->getUsername(); $this->add(['name' => 'username', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $validationUsernameOptions['length']['min'], 'max' => $validationUsernameOptions['length']['max']]], ['name' => 'Alnum'], $this->getUsernameValidator(), $this->getUserNameBackendNotExistsValidator()]]); $this->add(['name' => 'email', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'EmailAddress', 'options' => ['allow' => Hostname::ALLOW_DNS, 'useMxCheck' => true, 'useDeepMxCheck' => true]], $this->getStriposValidator()]]); if (!$this->collection->getRegisterOptions()->isDuplicateEmail()) { $element = $this->get('email'); /** @var \Zend\Validator\ValidatorChain $chain */ $chain = $element->getValidatorChain(); $chain->attach($this->getEmailValidator()); $element->setValidatorChain($chain); } $this->add(['name' => 'emailVerify', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => 6, 'max' => 255]], ['name' => 'Identical', 'options' => ['token' => 'email']]]]); $passwordLengthOptions = $this->collection->getPasswordOptions()->getLength(); $this->add(['name' => 'password', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], new Validator\PasswordRules($this->collection->getPasswordOptions())]]); $this->add(['name' => 'passwordVerify', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], ['name' => 'Identical', 'options' => ['token' => 'password']], new Validator\PasswordRules($this->collection->getPasswordOptions())]]); if ($this->collection->getPasswordOptions()->isSecretQuestion()) { $this->add(['name' => 'question', 'required' => true, 'validators' => [['name' => 'InArray', 'options' => ['haystack' => $this->getSecretQuestionList()]]]]); $this->add(['name' => 'answer', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => 3, 'max' => 255]]]]); } }
/** * read from the config if system works for secret question * @return boolean */ public function isSecretQuestionOption() { return $this->collectionOptions->getPasswordOptions()->isSecretQuestion(); }