public function setnewpasswordAction() { if ($this->request->isPost()) { $uniq = $this->request->getPost("uniq"); $url = Tmprecoverpassword::findFirst(array('conditions' => 'idTmprecoverpassword = ?1', 'bind' => array(1 => $uniq))); $time = strtotime("-30 minutes"); if (!$url && $url->date <= $time) { $this->flashSession->success('El tiempo para recuperar su contraseña, ha caducado, por favor haga el proceso desde cero'); return $this->response->redirect('session/login'); } $password1 = $this->request->getPost("password1"); $password2 = $this->request->getPost("password2"); if (empty($password1) || empty($password2)) { $this->flashSession->error("No has enviado las contraseñas"); return $this->response->redirect('session/resetpassword/' . $uniq); } if (strlen($password1) < 8 || strlen($password2) > 40) { $this->flashSession->error("La contraseña es muy corta o muy larga, esta debe tener mínimo 8 y máximo 40 caracteres, por favor verifique la información"); return $this->response->redirect('session/resetpassword/' . $uniq); } if ($password1 !== $password2) { $this->flashSession->error("Las contraseñas no coinciden, por favor verifique la información"); return $this->response->redirect('session/resetpassword/' . $uniq); } $idUser = $this->session->get('idUser'); $credential = Credential::findFirst(array('conditions' => 'idUser = ?1', 'bind' => array(1 => $idUser))); if (!$credential) { $this->flashSession->error("No existe el usuario, por favor valida la información"); return $this->response->redirect('session/login'); } $credential->password = $this->hash->hash($password1); if (!$credential->save()) { $this->flashSession->notice('Ha ocurrido un error, contacte con el administrador'); foreach ($user->getMessages() as $msg) { $this->logger->log('Error while recovering user password' . $msg); } } $this->flashSession->notice('Se ha actualizado el usuario exitosamente'); return $this->response->redirect('session/login'); } }