我在注册表中实施了reCaptcha。但是当我查看正确的验证码时,我收到了一个错误:
CCaptchaValidator.action“captcha”无效。无法在当前控制器中找到此类操作。
public function actionCreate()
{
$model=new TblUsers;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['TblUsers']))
{
Yii::import('ext.recaptchalib',true);
$privatekey = '6LfgNLoSAAAAAGBVyqeKK9qH_wG5HIGIDd2KotLB';
$resp = recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'],
Yii::app()->request->getParam('recaptcha_challenge_field'),
Yii::app()->request->getParam('recaptcha_response_field' ) );
$model->attributes=$_POST['TblUsers'];
if($resp->is_valid)
{
if($model->save())
if($this->_identity===null)
{
$this->_identity=new UserIdentity($model->username,$model->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
$this->redirect(array('site/index'));
return true;
}
else
return false;
}
}
else
{
$this->render('create',array(
'model'=>$model,
));
}
}
上面的代码是我的控制器,我检查验证码。如果没问题,那么他应该使用新创建的用户将数据保存在数据库中并登录。如果错误的代码,现在我只得到一个空白的白页。可能需要一些帮助。
快速编辑:Ups我用正确的代码解决了问题,我在模型规则中留下了一些垃圾,但它现在很好。甚至以为我仍然需要一些帮助来处理代码错误的事情,因为我现在得到一个空白页面。
答案 0 :(得分:1)
只是呈现错误的不同页面或重定向到其他页面而不进行任何用户登录操作。
如果$ resp不正确,您现在只是返回false。在这种情况下,您不会渲染任何内容。所以要么呈现错误页面
$this->render(......)
或重定向到另一个页面,并且不再采取任何操作进行登录或事件呈现相同,同时在验证码的表单字段上出现错误。
作为一个建议,看一下你的if语句的嵌套,这是一个简单的动作,你使它有点过于复杂。