public function resetAction() { if ($this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser'); } $this->passwordService->cleanExpiredForgotRequests(); $form = $this->getResetForm(); $userId = $this->params()->fromRoute('userId', null); $token = $this->params()->fromRoute('token', null); $passwordRequest = $this->passwordService->getPasswordMapper()->findByUserIdRequestKey($userId, $token); //no request for a new password found if ($passwordRequest === null || $passwordRequest == false) { return $this->redirect()->toRoute('zfcuser/forgotpassword'); } $user = $this->userService->getUserMapper()->findById($userId); if ($this->getRequest()->isPost()) { $form->setData($this->getRequest()->getPost()); if ($form->isValid() && $user !== null) { $this->passwordService->resetPassword($passwordRequest, $user, $form->getData()); $vm = new ViewModel(array('email' => $user->getEmail())); $vm->setTemplate('goalio-forgot-password/forgot/passwordchanged'); return $vm; } } // Render the form return new ViewModel(array('resetForm' => $form, 'userId' => $userId, 'token' => $token, 'email' => $user->getEmail())); }
public function testRemove_WillReturnTrue_IfUserExists() { $passWordEntity = new \GoalioForgotPassword\Entity\Password(); $passWordEntity->setUserId(10)->setRequestKey('test'); $now = date('Y-m-d'); $sql = "INSERT INTO user_password_reset('user_id', 'request_key', 'request_time') VALUES(10, 'test', {$now})"; $this->dbQuery($sql); $this->assertTrue($this->passwordService->remove($passWordEntity)); $this->assertEquals(0, $this->dbQuery("SELECT * FROM user_password_reset")->count()); }