示例#1
0
 public function proceed($userId, $tokenHash)
 {
     /** @var UserInterface $user */
     $user = $this->userRepository->findOneBy(array('id' => new \MongoId($userId), 'tokens.hash' => $tokenHash));
     if (!$user) {
         throw new UserNotFoundException('User or token does not exists');
     }
     $this->checkAllTokens($user, $tokenHash);
     $this->authenticationService->getStorage()->write($user->getId());
 }
示例#2
0
 public function proceed($userId)
 {
     if (!($user = $this->userRepository->find($userId))) {
         throw new Exception\UserNotFoundException('User cannot be found');
     }
     /* \Auth\Entity\Info */
     $user->getInfo()->setEmailVerified(true);
     $user->setEmail($user->getInfo()->getEmail());
     // Set verified email as primary email.
     $this->userRepository->store($user);
     $this->authenticationService->getStorage()->write($user->getId());
 }
示例#3
0
 /**
  * Edit user
  *
  * @return \Zend\Http\Response|ViewModel
  */
 public function editAction()
 {
     /* @var $user \Auth\Entity\User */
     $user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]);
     // check if user is not found
     if (!$user) {
         return $this->notFoundAction();
     }
     $params = $this->params();
     $serviceLocator = $this->serviceLocator;
     $forms = $serviceLocator->get('forms');
     /* @var $infoContainer \Auth\Form\UserProfileContainer */
     $infoContainer = $forms->get('Auth/userprofilecontainer');
     $infoContainer->setEntity($user);
     $statusContainer = $forms->get('Auth/UserStatusContainer');
     $statusContainer->setEntity($user);
     // set selected user to image strategy
     $imageStrategy = $infoContainer->getForm('info.image')->getHydrator()->getStrategy('image');
     $fileEntity = $imageStrategy->getFileEntity();
     $fileEntity->setUser($user);
     $imageStrategy->setFileEntity($fileEntity);
     if ($this->request->isPost()) {
         $formName = $params->fromQuery('form');
         $container = $formName === 'status' ? $statusContainer : $infoContainer;
         $form = $container->getForm($formName);
         if ($form) {
             $postData = $form->getOption('use_post_array') ? $params->fromPost() : [];
             $filesData = $form->getOption('use_files_array') ? $params->fromFiles() : [];
             $form->setData(array_merge($postData, $filesData));
             if (!$form->isValid()) {
                 return new JsonModel(array('valid' => false, 'errors' => $form->getMessages()));
             }
             $serviceLocator->get('repositories')->store($user);
             if ('file-uri' === $params->fromPost('return')) {
                 $content = $form->getHydrator()->getLastUploadedFile()->getUri();
             } else {
                 if ($form instanceof SummaryFormInterface) {
                     $form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY);
                     $viewHelper = 'summaryform';
                 } else {
                     $viewHelper = 'form';
                 }
                 $content = $serviceLocator->get('ViewHelperManager')->get($viewHelper)->__invoke($form);
             }
             return new JsonModel(array('valid' => $form->isValid(), 'content' => $content));
         }
     }
     return ['infoContainer' => $infoContainer, 'statusContainer' => $statusContainer];
 }
示例#4
0
 /**
  * @todo remove unused $mailer parameter an fix tests
  *
  * @param InputFilterInterface $filter
  * @param Plugin\Mailer $mailer
  * @param Url $url
  * @throws \LogicException
  * @throws UserDoesNotHaveAnEmailException
  * @throws UserNotFoundException
  */
 public function proceed(InputFilterInterface $filter, Plugin\Mailer $mailer, Url $url)
 {
     if (!$filter->isValid()) {
         throw new \LogicException('Form is not valid');
     }
     $identity = $filter->getValue('identity');
     $suffix = $this->loginFilter->filter();
     if (!($user = $this->userRepository->findByLoginOrEmail($identity, $suffix))) {
         throw new UserNotFoundException('User is not found');
     }
     if (!($email = $user->getInfo()->getEmail())) {
         throw new UserDoesNotHaveAnEmailException('User does not have an email');
     }
     $tokenHash = $this->tokenGenerator->generate($user);
     $resetLink = $url->fromRoute('lang/goto-reset-password', array('token' => $tokenHash, 'userId' => $user->getId()), array('force_canonical' => true));
     $e = new AuthEvent();
     $e->setResetLink($resetLink);
     $e->setUser($user);
     $this->eventManager->trigger(AuthEvent::EVENT_AUTH_NEWPASSWORD, $e);
 }