
Untitled
By: a guest on
Jul 22nd, 2012 | syntax:
None | size: 1.36 KB | hits: 16 | expires: Never
Yii framework: reCaptcha
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,
));
}
}
$this->render(......)