public function editarAction()
 {
     Zend_Loader::loadClass('Zend_Auth');
     $authClass = Zend_Auth::getInstance();
     if ($authClass->hasIdentity()) {
         $auth = $authClass->getStorage()->read();
         $id = $auth['usuario_id'];
         $usuarioModel = new Application_Model_Usuario();
         $usuario = $usuarioModel->find($id)->current();
     }
     if (isset($usuario)) {
         //$user = $usuario['usuario'];
         $user = $auth['usuario_id'];
         $enderecoModel = new Application_Model_Endereco();
         $row = $enderecoModel->fetchRow($enderecoModel->select()->where('usuario = ?', $user));
         if ($row->completo = '0') {
             $this->view->endereco = '1';
         } else {
             $this->view->endereco = '0';
         }
         $contatoModel = new Application_Model_Contato();
         $rowdois = $contatoModel->fetchRow($contatoModel->select()->where('usuario = ?', $user));
         if ($rowdois->completo = '0') {
             $this->view->contato = '1';
         } else {
             $this->view->contato = '0';
         }
     }
 }
 public function esqueciAction()
 {
     require_once APPLICATION_PATH . '/forms/Esqueci.php';
     $this->view->form = new Application_Form_Esqueci();
     if ($this->_request->isPost()) {
         $this->view->form->setDefaults($this->_request->getPost());
         $data = $this->view->form->getValues();
         $usuarioModel = new Application_Model_Usuario();
         if ($this->view->form->isValid($data)) {
             $resetModel = new Application_Model_Reset();
             $row = $resetModel->fetchRow($resetModel->select()->where('usuario = ?', $data['usuario']));
             if ($row != null) {
                 $this->view->aviso = 'Voce ja pediu um codigo para esse usuario';
             } else {
                 /// function to generate random number ///////////////
                 function random_generator($digits)
                 {
                     srand((double) microtime() * 10000000);
                     //Array of alphabets
                     $input = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
                     $random_generator = "";
                     // Initialize the string to store random numbers
                     for ($i = 1; $i < $digits + 1; $i++) {
                         // Loop the number of times of required digits
                         if (rand(1, 2) == 1) {
                             // to decide the digit should be numeric or alphabet
                             // Add one random alphabet
                             $rand_index = array_rand($input);
                             $random_generator .= $input[$rand_index];
                             // One char is added
                         } else {
                             // Add one numeric digit between 1 and 10
                             $random_generator .= rand(1, 10);
                             // one number is added
                         }
                         // end of if else
                     }
                     // end of for loop
                     return $random_generator;
                 }
                 // end of function
                 $key = random_generator(10);
                 $key = md5($key);
                 $data['key'] = $key;
                 $resetModel = new Application_Model_Reset();
                 $id = $resetModel->insert($data);
                 Zend_Loader::loadClass('Zend_Auth');
                 $authClass = Zend_Auth::getInstance();
                 $auth = $authClass->getStorage()->read();
                 $user = $data['usuario'];
                 $contatoModel = new Application_Model_Contato();
                 $row = $contatoModel->fetchRow($contatoModel->select()->where('usuario = ?', $user));
                 $mail = $row['email'];
                 //envia e-mail
                 $data = 'Seu código para redefinição de senha é: ' . $key . '<br/>Seu usuário é: ' . $user;
                 // Using the ini_set()
                 ini_set("SMTP", "localhost");
                 ini_set("sendmail_from", "*****@*****.**");
                 ini_set("smtp_port", "587");
                 $mail = new Zend_Mail('UTF-8', 'ISO-8859-8');
                 $mail->setBodyHtml($data)->setFrom('*****@*****.**', 'Online Thru')->addTo($mail, 'Contato')->setSubject('Redefinição de senha - Online Thru')->send();
                 $this->view->aviso = 'O código para redefinição de senha foi enviado para o e-mail ' . $mail;
             }
         }
     }
 }