public function recoverpasswordAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost("email");
         $user = User::findFirst(array('conditions' => 'email = ?1', 'bind' => array(1 => $email)));
         if ($user) {
             $cod = uniqid();
             $url = $this->urlManager->getBaseUrl(true);
             $url .= "session/resetpassword/{$cod}";
             $recover = new Tmprecoverpassword();
             $recover->idTmprecoverpassword = $cod;
             $recover->idUser = $user->idUser;
             $recover->url = $url;
             $recover->date = time();
             if (!$recover->save()) {
                 $this->logger->log("Error while saving tmp recover password url {$user->idUser}/{$user->username}");
                 foreach ($recover->getMessages() as $msg) {
                     $this->logger->log('Msg: ' . $msg);
                 }
                 $this->flashSession->error('Ha ocurrido un error contacte al administrador');
             } else {
                 $link = '<a href="' . $url . '" style="text-decoration: underline;">Click aqui</a>';
                 try {
                     $message = new \Silar\Misc\AdministrativeMessages();
                     $message->setSmtp($this->smtpsupport);
                     $message->setSubject("Instrucciones para recuperar la contraseña de su cuenta en Cluster Solutions - Silar");
                     $message->setTo(array($user->email => "{$user->name} {$user->lastName}"));
                     $message->setReplyTo("*****@*****.**");
                     $message->searchMessage('reset-password');
                     $message->replaceVariables(array('%%resetpassword%%'), array($link));
                     $message->sendMessage();
                 } catch (Exception $ex) {
                     $this->logger->log("Exception: {$ex}");
                     $this->flashSession->error('Ha ocurrido un error contacte al administrador');
                 }
             }
         }
         $this->flashSession->success('Se ha enviado un correo electronico con instrucciones para recuperar la contraseña');
         return $this->response->redirect('session/login');
     }
 }
Esempio n. 2
0
 public function recoverpasswordAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost("email");
         $credential = Credential::findFirst(array('conditions' => 'email = ?1', 'bind' => array(1 => $email)));
         if ($credential) {
             $user = User::findFirstByIdUser($credential->idUser);
             $cod = uniqid();
             $urlManager = $urlManager = Phalcon\DI::getDefault()->get('urlManager');
             $url = $urlManager->getBaseUri(true);
             $url .= 'session/reset/' . $cod;
             $tmprecoverpassword = new Tmprecoverpassword();
             $tmprecoverpassword->idTmprecoverpassword = $cod;
             $tmprecoverpassword->idUser = $user->idUser;
             $tmprecoverpassword->url = $url;
             $tmprecoverpassword->date = time();
             if (!$tmprecoverpassword->save()) {
                 foreach ($tmprecoverpassword->getMessages() as $msg) {
                     $this->logger->log('Msg: ' . $msg);
                 }
                 $this->flashSession->error('Ha ocurrido un error contacte al administrador');
             } else {
                 $link = '<a href="' . $url . '" style="text-decoration: underline;">Click aqui</a>';
                 try {
                     $this->logger->log($link);
                     $NotificationMail = new \Sayvot\Misc\NotificationMail();
                     $NotificationMail->createRecoverpasswordMail($credential->email, $link);
                     $NotificationMail->sendMail();
                 } catch (Exception $e) {
                     $this->logger->log('Exception: ' . $e->getMessage());
                     $this->flashSession->error('Ha ocurrido un error contacte al administrador');
                 }
             }
         }
         $this->flashSession->success('Se ha enviado un correo electronico con instrucciones para recuperar la contraseña');
         return $this->response->redirect('session/login');
     }
 }