Esempio n. 1
0
 /**
  * @param UserInterface $user
  * @return bool
  */
 protected function isSecretLogin(UserInterface $user)
 {
     $result = false;
     $secretLoginRoleList = $this->collectionOptions->getLoginOptions()->getSecretLoginRoleList();
     if ($secretLoginRoleList && ($userRoles = $user->getRoles())) {
         $secretLoginRoleList = array_map('strtolower', $secretLoginRoleList);
         foreach ($userRoles as $userRole) {
             if (in_array(strtolower($userRole->getRoleId()), $secretLoginRoleList)) {
                 $code = $this->userCodeService->setCode4User($user, UserCodesEntity::TYPE_SECRET_LOGIN);
                 $this->mailService->secretLogin($user, $code);
                 $this->getFlashMessenger()->setNamespace($this::ERROR_NAME_SPACE)->addMessage('Please confirm your secret-login with your email');
                 $result = true;
             }
         }
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * @param $data
  * @param UserInterface $user
  * @return bool
  */
 public function addEmail($data, UserInterface $user)
 {
     $form = $this->getAddEmailForm();
     $form->setData($data);
     if (!$form->isValid()) {
         foreach ($form->getElements() as $messages) {
             /** @var \Zend\Form\ElementInterface $messages */
             foreach ($messages->getMessages() as $message) {
                 $this->getFlashMessenger()->setNamespace(self::ERROR_NAMESPACE)->addMessage($message);
             }
         }
         return false;
     }
     $user = $this->getUser4Id($user->getId());
     if ($user->getEmail()) {
         $this->getFlashMessenger()->setNamespace(self::ERROR_NAMESPACE)->addMessage('Email already exists in your Account');
         return false;
     }
     $data = $form->getData();
     $entityManager = $this->entityManager;
     if ($this->collectionOptions->getRegisterOptions()->isMailConfirmation()) {
         $userExtensionName = $this->collectionOptions->getEntityOptions()->getUserExtension();
         /** @var \PServerCore\Entity\UserExtension $userExtension */
         $userExtension = new $userExtensionName();
         /** @var \PServerCore\Entity\Repository\UserExtension $extensionRepository */
         $extensionRepository = $entityManager->getRepository($userExtensionName);
         $extensionRepository->deleteExtension($user, $userExtension::KEY_ADD_EMAIL);
         $userExtension->setKey($userExtension::KEY_ADD_EMAIL)->setUser($user)->setValue($data['email']);
         $entityManager->persist($userExtension);
         $entityManager->flush();
         $code = $this->userCodeService->setCode4User($user, UserCodesEntity::TYPE_ADD_EMAIL);
         $user->setEmail($data['email']);
         $this->mailService->addEmail($user, $code);
         $this->getFlashMessenger()->setNamespace(self::SUCCESS_NAMESPACE)->addMessage('Success, please confirm your mail.');
     } else {
         $user->setEmail($data['email']);
         $entityManager->persist($user);
         $entityManager->flush();
         $this->authService->getStorage()->write($user);
     }
     return true;
 }