public function testRemoveIfExistsFromPostData()
 {
     $data = array('abc' => 'def');
     $sanitizedData = UserStatusUtil::removeIfExistsFromPostData($data);
     $this->assertEquals($sanitizedData, $data);
     $sanitizedData = UserStatusUtil::removeIfExistsFromPostData(array('abc' => 'def', 'userStatus' => 'abc'));
     $this->assertEquals($sanitizedData, $data);
 }
Exemplo n.º 2
0
 /**
  * Override to handle UserStatus processing.
  * @see ZurmoBaseController::attemptToSaveModelFromPost()
  */
 protected function attemptToSaveModelFromPost($model, $redirectUrlParams = null, $redirect = true, $returnOnValidate = false)
 {
     assert('$model instanceof User || $model instanceof UserPasswordForm || $model instanceof UserAvatarForm');
     assert('$redirectUrlParams == null || is_array($redirectUrlParams) || is_string($redirectUrlParams)');
     $postVariableName = get_class($model);
     if (isset($_POST[$postVariableName])) {
         $postData = $_POST[$postVariableName];
         if (isset($_POST[$postVariableName]['userStatus'])) {
             $userStatus = UserStatusUtil::makeByPostData($_POST[$postVariableName]);
             $sanitizedPostdata = UserStatusUtil::removeIfExistsFromPostData($postData);
         } else {
             $userStatus = null;
             $sanitizedPostdata = $postData;
         }
         $savedSucessfully = false;
         $modelToStringValue = null;
         $oldUsername = $model->username;
         $controllerUtil = new ZurmoControllerUtil();
         $model = $controllerUtil->saveModelFromPost($sanitizedPostdata, $model, $savedSucessfully, $modelToStringValue);
         if ($savedSucessfully) {
             if ($userStatus != null) {
                 if ($model instanceof UserPasswordForm || $model instanceof UserAvatarForm) {
                     UserStatusUtil::resolveUserStatus($model->getModel(), $userStatus);
                 } else {
                     UserStatusUtil::resolveUserStatus($model, $userStatus);
                 }
             }
             if ($model->id == Yii::app()->user->userModel->id && $model->username != $oldUsername) {
                 //If the logged in user changes their username, a logout must occur to properly to properly
                 //restart the session.
                 Yii::app()->getSession()->destroy();
                 $this->redirect(Yii::app()->homeUrl);
             }
             $this->actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams);
         }
     }
     return $model;
 }