/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Propietario();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Propietario'])) {
         $model->attributes = $_POST['Propietario'];
         $usuario = new Usuario();
         $model->rut = Tools::removeDots($model->rut);
         $usuario->user = $model->rut;
         $arr = explode("-", $model->rut);
         $usuario->clave = CPasswordHelper::hashPassword($arr[0]);
         $usuario->rol = "propietario";
         $usuario->nombre = $_POST['Propietario']['nombre'];
         $usuario->email = $_POST['Propietario']['email'];
         $usuario->apellido = $_POST['Propietario']['apellido'];
         $model->usuario_id = 1;
         if ($model->validate()) {
             if ($usuario->validate()) {
                 if ($usuario->save()) {
                     $model->usuario_id = $usuario->id;
                     if ($model->save()) {
                         $auth = Yii::app()->authManager;
                         Authassignment::model()->deleteAllByAttributes(array('userid' => $usuario->id));
                         $auth->revoke($usuario->rol, $model->usuario_id);
                         $auth->assign($usuario->rol, $model->usuario_id);
                         $this->redirect(array('view', 'id' => $model->id));
                     }
                 }
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
 * Creates a new model.
 * If creation is successful, the browser will be redirected to the 'view' page.
 */
 public function actionCreate()
 {
     $model = new Propietario();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Propietario'])) {
         $model->attributes = $_POST['Propietario'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id_propietario));
         }
     }
     $this->render('create', array('model' => $model));
 }