激活表单不完全有效

时间:2013-10-17 01:23:58

标签: zend-framework-modules

我希望有人可以帮忙解决这个问题。有一次,我认为我有这个工作,但无法弄清楚为什么它不是。

下面的脚本会执行除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'));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我发现了错误。我不知何故没有将变量encoded_link放入路径下该模块的.ini文件中。