fix bug #81. 修复登录用户不能留言的问题

This commit is contained in:
wlx 2009-12-25 09:33:09 +00:00
parent 64e4616cab
commit 125d2d97ce
2 changed files with 6 additions and 13 deletions

View File

@ -557,16 +557,11 @@ class DataController extends Zend_Controller_Action
$user=Zend_Auth::getInstance()->getIdentity(); $user=Zend_Auth::getInstance()->getIdentity();
$commentForm=new CommentForm(); $commentForm=new CommentForm();
$formdata['uuid']=$uuid; $formdata['uuid']=$uuid;
$formdata['id']=0;//用户ID默认为0即未登录用户 $formdata['uid']=0;//用户ID默认为0即未登录用户
$this->view->addHelperPath('helper','Zend_View_Helper_'); $this->view->addHelperPath('helper','Zend_View_Helper_');
if ($this->_request->isPost()) { if ($this->_request->isPost()) {
include_once("bcspamblock.php"); include_once("bcspamblock.php");
$formdata=$this->_request->getPost(); $formdata=$this->_request->getPost();
if ($user) {
$formdata['id']=$user->id;
$formdata['author']=$user->username;
$formdata['email']=$user->email;
}
if (bcspamblock_verify() && $commentForm->isValid($formdata)) { if (bcspamblock_verify() && $commentForm->isValid($formdata)) {
$sql="insert into comments (userid,uuid,author,email,url,ip,content,agent,type) values(?,?,?,?,?,?,?,?,?)"; $sql="insert into comments (userid,uuid,author,email,url,ip,content,agent,type) values(?,?,?,?,?,?,?,?,?)";
$agent=$this->_request->getHeader('User-Agent'); $agent=$this->_request->getHeader('User-Agent');
@ -575,12 +570,11 @@ class DataController extends Zend_Controller_Action
$stripper = new Zend_Filter_StripTags('strong');//剔除特殊字符HTML $stripper = new Zend_Filter_StripTags('strong');//剔除特殊字符HTML
$content=$stripper->filter($formdata['content']); $content=$stripper->filter($formdata['content']);
$author=$stripper->filter($formdata['author']); $author=$stripper->filter($formdata['author']);
$this->db->query($sql,array($formdata['id'],$formdata['uuid'],$author,$formdata['email'],$formdata['url'],$ip,$content,$agent,$type)); $this->db->query($sql,array($formdata['uid'],$formdata['uuid'],$author,$formdata['email'],$formdata['url'],$ip,$content,$agent,$type));
$formdata['content']=''; $formdata['content']='';
} }
} } elseif ($user) {
if ($user) { $formdata['uid']=$user->id;
$formdata['id']=$user->id;
$formdata['author']=$user->username; $formdata['author']=$user->username;
$formdata['email']=$user->email; $formdata['email']=$user->email;
} }

View File

@ -27,7 +27,7 @@ class CommentForm extends Zend_Form
$spam->addPrefixPath('Validator','validator/','validate') $spam->addPrefixPath('Validator','validator/','validate')
->addValidator('SpamBlock'); ->addValidator('SpamBlock');
$id = new Zend_Form_Element_Hidden('id'); $uid = new Zend_Form_Element_Hidden('uid');
$uuid = new Zend_Form_Element_Hidden('uuid'); $uuid = new Zend_Form_Element_Hidden('uuid');
$redirect=new Zend_Form_Element_Hidden('redirect'); $redirect=new Zend_Form_Element_Hidden('redirect');
@ -35,8 +35,7 @@ class CommentForm extends Zend_Form
$submit = new Zend_Form_Element_Submit('submit'); $submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('评论'); $submit->setLabel('评论');
$submit->setAttrib('id', 'commentbutton'); $submit->setAttrib('id', 'commentbutton');
$this->addElements(array($author,$email, $url, $spam, $content, $submit,$id, $uuid)); $this->addElements(array($author,$email, $url, $spam, $content, $submit,$uid, $uuid));
$this->clearDecorators(); $this->clearDecorators();
$this->addDecorator('FormElements') $this->addDecorator('FormElements')
->addDecorator('HtmlTag', array('tag' => '<ul>','class'=>'commentform')) ->addDecorator('HtmlTag', array('tag' => '<ul>','class'=>'commentform'))