Esempio n. 1
0
 public function definirSenhaAction()
 {
     $this->_helper->layout->setLayout('twbs3/front-page');
     $hashedToken = $this->getRequest()->getParam('hashedToken');
     if (empty($hashedToken)) {
         $this->_helper->flashMessenger->addMessage(array('warning' => _('Verification token not informed.')));
         return $this->_helper->redirector->goToRoute(array(), 'login', true);
     }
     $id = $this->getRequest()->getParam('id');
     if (empty($id)) {
         $this->_helper->flashMessenger->addMessage(array('warning' => _('User not informed.')));
         return $this->_helper->redirector->goToRoute(array(), 'login', true);
     }
     $pessoa = new Application_Model_Pessoa();
     try {
         $pessoa->verificarToken($id, $hashedToken);
     } catch (Exception $e) {
         $this->_helper->flashMessenger->addMessage(array('danger' => $e->getMessage()));
         return $this->_helper->redirector->goToRoute(array(), 'login', true);
     }
     $form = new Application_Form_DefinirSenha();
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         $values = $form->getValues();
         try {
             if (strcmp($values['nova_senha'], $values['repetir_nova_senha']) == 0) {
                 $pessoa->setNovaSenha($id, $values['nova_senha']);
                 $pessoa->resetarToken($id);
                 $this->_helper->flashMessenger->addMessage(array('success' => _('Password successfully updated!')));
                 return $this->_helper->redirector->goToRoute(array(), 'login', true);
             } else {
                 $this->_helper->flashMessenger->addMessage(array('warning' => _('The passwords must match!')));
             }
         } catch (Exception $e) {
             $this->_helper->flashMessenger->addMessage(array('danger' => $e->getMessage()));
         }
     }
     // cria form e envia pra view
     $this->view->form = $form;
 }