/**
  * register user
  * Enter description here ...
  */
 function actionUpdateProfile()
 {
     header('Content-type: application/json');
     //	    if(!Yii::app()->request->isPostRequest){
     //	   		 IjoyPlusServiceUtils::exportServiceError(Constants::METHOD_NOT_SUPPORT);
     //	   		 return ;
     //	   	}
     if (!IjoyPlusServiceUtils::validateAPPKey()) {
         IjoyPlusServiceUtils::exportServiceError(Constants::APP_KEY_INVALID);
         return;
     }
     $nickname = Yii::app()->request->getParam("nickname");
     $pwd = Yii::app()->request->getParam("password");
     $username = Yii::app()->request->getParam("username");
     $sourceid = Yii::app()->request->getParam("source_id");
     $source_type = Yii::app()->request->getParam("source_type");
     if (!IjoyPlusServiceUtils::validateThirdPartSource($source_type)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::THIRD_PART_SOURCE_TYPE_INVALID);
         return;
     }
     if (!(isset($nickname) && !is_null($nickname) && strlen($nickname) > 0)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::NICKNAME_IS_NULL);
         return;
     }
     if (!(isset($pwd) && !is_null($pwd) && strlen($pwd) > 0)) {
         IjoyPlusServiceUtils::exportServiceError(Constants::PWD_IS_NULL);
         return;
     }
     if (isset($username) && !is_null($username) && strlen($username) > 0) {
         $emailValidator = new CEmailValidator();
         if (!$emailValidator->validateValue($username)) {
             IjoyPlusServiceUtils::exportServiceError(Constants::EMAIL_INVALID);
             return;
         } else {
             $record = User::model()->find('LOWER(username)=?', array(strtolower($username)));
             if ($record !== null) {
                 IjoyPlusServiceUtils::exportServiceError(Constants::USERNAME_EXIST);
                 return;
             }
         }
     }
     try {
         $record = User::model()->find('LOWER(nickname)=?', array(strtolower($nickname)));
         if ($record !== null) {
             IjoyPlusServiceUtils::exportServiceError(Constants::NICKNAME_IS_EXSTING);
             return;
         } else {
             $model = new User();
             $model->nickname = $nickname;
             $model->password = md5($pwd);
             $model->username = $username;
             $model->status = Constants::USER_APPROVAL;
             $model->create_date = new CDbExpression('NOW()');
             switch ($source_type) {
                 case Constants::THIRD_PART_ACCOUNT_DOUBAN:
                     $model->douban_user_id = $sourceid;
                     break;
                 case Constants::THIRD_PART_ACCOUNT_QQ:
                     $model->qq_wb_user_id = $sourceid;
                     break;
                 case Constants::THIRD_PART_ACCOUNT_REN_REN:
                     $model->ren_user_id = $sourceid;
                     break;
                 case Constants::THIRD_PART_ACCOUNT_SINA:
                     $model->sina_wb_user_id = $sourceid;
                     break;
             }
             if ($model->save()) {
                 $identity = new IjoyPlusUserIdentity($username, $pwd);
                 $identity->setId($model->id);
                 $identity->setState('nickname', $model->nickname);
                 Yii::app()->user->login($identity);
                 UserManager::followPrestiges($model->id);
                 IjoyPlusServiceUtils::exportServiceError(Constants::SUCC);
                 //
             } else {
                 Yii::log(CJSON::encode($model->getErrors()), "warning");
                 //   		    	var_dump();
                 IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
             }
         }
     } catch (Exception $e) {
         Yii::log(CJSON::encode($e), "error");
         IjoyPlusServiceUtils::exportServiceError(Constants::SYSTEM_ERROR);
     }
 }
 private static function login($userid)
 {
     $user = User::model()->findUser($userid);
     if ($user !== false && isset($user) && !is_null($user)) {
         $identity = new IjoyPlusUserIdentity($user['username'], '');
         $identity->setId($userid);
         $identity->setState('nickname', $user['nickname']);
         $identity->setState('pic_url', $user['user_photo_url']);
         Yii::app()->user->login($identity);
         return false;
     } else {
         return true;
     }
 }