2013-10-17 114 views
0

我希望有人能幫助解決這個問題。有一次,我以爲我有這個工作,但不知道爲什麼它不是。激活表單不能正常工作

下面的腳本除了包含Zend_Json :: encode以外,什麼都做。它將用戶保存在數據庫中,並通過電子郵件發送給該用戶一個鏈接,但該鏈接沒有包含在其中的加密。

感謝您的幫助!

public function contribjoinAction() 
{ 
    $request = $this->getRequest(); 

    $conn = XXX_Db_Connection::factory()->getMasterConnection(); 
    $userDao = XXX_Model_Dao_Factory::getInstance()->setModule('core')->getUserDao(); 
    $userDao->setDbConnection($conn); 

    if ($request->isPost()) { 
     $fullname = $request->getPost('full_name'); 
     $username = $request->getPost('username'); 
     $password = $request->getPost('password'); 
     $password2 = $request->getPost('confirmPassword'); 
     $email  = $request->getPost('email'); 
     $islegal = $request->getPost('islegal'); 

     $user = new Core_Models_User(array(
      'user_name'  => $username, 
      'password'  => $password, 
      'full_name'  => $fullname, 
      'email'   => $email, 
      'is_active'  => 0, 
      'created_date' => date('Y-m-d H:i:s'), 
      'logged_in_date' => null, 
      'is_online'  => 0, 
      'role_id'  => 2, 
      'islegal'  => $islegal, 
     )); 
     $id = $userDao->add($user); 

     $templateDao = XXX_Model_Dao_Factory::getInstance()->setModule('mail')->getTemplateDao(); 
      $templateDao->setDbConnection($conn); 
      $template = $templateDao->getByName(Mail_Models_Template::TEMPLATE_ACTIVATE_CONTRIBUTOR); 

      if ($template == null) { 
       $message = sprintf($this->view->translator('auth_mail_template_not_found'), Mail_Models_Template::TEMPLATE_ACTIVATE_CONTRIBUTOR); 
       throw new Exception($message); 
      } 

      $search = array(Mail_Models_Mail::MAIL_VARIABLE_EMAIL, Mail_Models_Mail::MAIL_VARIABLE_USERNAME); 
      $replace = array($user->email, $user->user_name); 
      $subject = str_replace($search, $replace, $template->subject); 
      $content = str_replace($search, $replace, $template->body); 

      /** 
      * Replace the reset password link 
      * @TODO: Add security key? 
      */ 


      $encodedLink = array(
       'email' => $email, 
       'user_name' => $username, 
      ); 

      $encodedLink = base64_encode(urlencode(Zend_Json::encode($encodedLink))); 
      $link  = $this->view->serverUrl() . $this->view->url(array('encoded_link' => $encodedLink), 'core_user_emailactivate'); 
      $content  = str_replace('%activate_link%', $link, $content); 

      /** 
      * Get mail transport instance 
      */ 
      $transport = Mail_Services_Mailer::getMailTransport(); 

      $mail = new Zend_Mail(); 
      $mail->setFrom($template->from_mail, $template->from_name)     
       ->addTo($user->email, $user->user_name) 
       ->setSubject($subject) 
       ->setBodyHtml($content) 
       ->send($transport); 
     if ($id > 0) { 
      $this->_helper->getHelper('FlashMessenger') 
       ->addMessage($this->view->translator('user_join_success')); 
      $this->_redirect($this->view->serverUrl() . $this->view->url(array(), 'core_user_contribjoin')); 
     } 
    } 
} 

回答

0

我發現了錯誤。我以某種方式沒有將變量encoded_link放入路由下該模塊的.ini文件中。