Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 22nd, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Yii framework: reCaptcha
  2. public function actionCreate()
  3. {
  4.     $model=new TblUsers;
  5.  
  6.     // Uncomment the following line if AJAX validation is needed
  7.         $this->performAjaxValidation($model);
  8.  
  9.     if(isset($_POST['TblUsers']))
  10.     {
  11.                 Yii::import('ext.recaptchalib',true);
  12.                 $privatekey = '6LfgNLoSAAAAAGBVyqeKK9qH_wG5HIGIDd2KotLB';
  13.                 $resp = recaptcha_check_answer($privatekey, $_SERVER['REMOTE_ADDR'],
  14.                         Yii::app()->request->getParam('recaptcha_challenge_field'),
  15.                         Yii::app()->request->getParam('recaptcha_response_field' ) );
  16.  
  17.         $model->attributes=$_POST['TblUsers'];
  18.                 if($resp->is_valid)
  19.                 {
  20.         if($model->save())
  21.                     if($this->_identity===null)
  22.     {
  23.         $this->_identity=new UserIdentity($model->username,$model->password);
  24.         $this->_identity->authenticate();
  25.     }
  26.     if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
  27.     {
  28.         $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
  29.         Yii::app()->user->login($this->_identity,$duration);
  30.                 $this->redirect(array('site/index'));
  31.  
  32.         return true;
  33.     }
  34.     else
  35.         return false;
  36.     }
  37.         }
  38.         else
  39.         {
  40.     $this->render('create',array(
  41.         'model'=>$model,
  42.     ));
  43.         }
  44.  
  45.  
  46. }
  47.        
  48. $this->render(......)