public function saveUserInfo($model, $modelProfile, $postUser, $postProfile, $role, $checkRole = true)
 {
     $password = $model->password;
     $model->attributes = $postUser;
     if ($checkRole) {
         //check valid roles
         $roleArray = array('Manager', 'Administrator', 'Super User');
         if (!in_array($role, $roleArray)) {
             throw new CHttpException(451, Yii::t('user', 'Roles is not a valid value.'));
         }
     }
     if ($model->validate()) {
         $transaction = Yii::app()->db->beginTransaction();
         try {
             //Does user enter a new password? Yes: encrypt, No: nothing change
             if (!empty($model->password)) {
                 $model->salt = Yii::app()->extraFunctions->randomString(32);
                 $model->password = Yii::app()->extraFunctions->encryptUserPassword($model->salt, $postUser['password']);
             } else {
                 $model->password = $password;
             }
             $avatarArray = explode('/', $postUser['avatar']);
             $model->avatar = $avatarArray[count($avatarArray) - 1];
             //user want to create new profile must enter several info
             if (empty($modelProfile->userid)) {
                 if (Yii::app()->extraFunctions->checkEmptyField($postProfile, 'sex')) {
                     $modelProfile->userid = $model->id;
                     $modelProfile->attributes = $postProfile;
                     $modelProfile->save();
                 }
             } else {
                 //user update his profile
                 $modelProfile->attributes = $postProfile;
                 $modelProfile->save();
             }
             if ($model->update()) {
                 //save role
                 if ($checkRole) {
                     Yii::import('application.modules.backend.controllers.AuthorizedController');
                     $t = new AuthorizedController($model->id);
                     if ($t->SaveRole($model->id, $role)) {
                         $transaction->commit();
                         return TRUE;
                     } else {
                         $transaction->rollback();
                     }
                 } else {
                     //nếu ko có thêm role thì commit luôn
                     $transaction->commit();
                     return TRUE;
                 }
             }
         } catch (Exception $ex) {
             $transaction->rollback();
         }
     }
     return FALSE;
 }