public function passwordRecoverAction() { $identityRepo = $this->entityManager->getRepository($this->config['identityClass']); $credentialRepo = $this->entityManager->getRepository($this->config['credentialClass']); $token = $this->params()->fromRoute('token', 0); if ($this->identity()) { $this->authenticationService->getStorage()->forgetMe(); $this->authenticationService->clearIdentity(); } $qb = $identityRepo->createQueryBuilder('i'); $qb->where('i.token = :token'); $qb->setParameter('token', $token); /** @var UserInterface $identity */ $identity = $qb->getQuery()->getOneOrNullResult(); if ($identity == null) { $this->flashMessenger()->addErrorMessage(_('Token invalid or you already confirmed this link.')); return $this->redirect()->toRoute($this->routes['signin']['name'], $this->routes['signin']['params'], $this->routes['signin']['options'], $this->routes['signin']['reuseMatchedParams']); } $form = new PasswordChangeForm(); $this->routes['password-recover']['params']['token'] = $token; $form->setAttribute('action', $this->url()->fromRoute($this->routes['password-recover']['name'], $this->routes['password-recover']['params'], $this->routes['password-recover']['options'], $this->routes['password-recover']['reuseMatchedParams'])); $form->getInputFilter()->get('password-old')->setRequired(false); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $credential = $credentialRepo->findOneBy(array($this->config['credentialIdentityProperty'] => $identity, 'type' => $this->config['credentialType'])); $passwordNew = sha1(sha1($data['password-new'])); $identity->setToken(sha1(uniqid(mt_rand(), true))); $credential->setValue($passwordNew); $this->entityManager->flush(); $this->flashMessenger()->addSuccessMessage(_('Your password has been changed successfully!')); return $this->redirect()->toRoute($this->routes['signin']['name'], $this->routes['signin']['params'], $this->routes['signin']['options'], $this->routes['signin']['reuseMatchedParams']); } else { $this->flashMessenger()->addErrorMessage(_('Form with errors!')); } } $form->prepare(); $viewModel = new ViewModel(['form' => $form, 'routes' => $this->routes]); $viewModel->setTemplate($this->templates['password-recover']); $this->layout($this->layoutView); return $viewModel; }