Ejemplo n.º 1
0
 /**
  * while clicking ther forgotpassword
  * a mail is send to user with a link to reset the new password
  */
 public function forgotpasswordAction()
 {
     $form = new User_Form_User_Forgotpassword();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $email = $form->getValue('email');
             $userModel = new User_Model_DbTable_User();
             $user = $userModel->getUserByEmail($email);
             if ($user) {
                 try {
                     $uniqueId = md5(uniqid());
                     $resetSite = "http://" . $_SERVER['HTTP_HOST'] . $this->view->baseUrl() . '/user/user/resetpassword/email/' . urlencode($email) . '/value/' . urlencode($uniqueId);
                     $reset = new User_Model_DbTable_Reset();
                     $reset->insert(array('email' => $email, 'value' => $uniqueId, 'reset_flag' => '1'));
                     $notification = new Model_Notification();
                     $notification->sendResetNotifications($user, $resetSite);
                     $this->_helper->FlashMessenger->addMessage(array('message' => 'Further instructions' . ' have been sent to your e-mail address.'));
                     $this->_redirect('/');
                 } catch (Exception $e) {
                     $this->_helper->FlashMessenger->addMessage(array('error' => 'Error in sending mail.'));
                 }
                 //end of try catch
             } else {
                 $this->_helper->FlashMessenger->addMessage(array('error' => 'Sorry, ' . $email . ' is not a registered email in AidStream.'));
             }
             //end of if
         } else {
             $form->populate($formData);
         }
     }
 }