/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AdmPersonas();
     //pepito.perez.1234
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['AdmPersonas'])) {
         $model->attributes = $_POST['AdmPersonas'];
         $modelAdmUsuarios = new AdmUsuarios();
         $modelAdmUsuarios->nombre = "{$model->nombreuno}.{$model->apellidouno}." . substr($model->nro_documento, strlen($model->nro_documento) - 4);
         $modelAdmUsuarios->contrasena = md5($_POST['confirmcontrasena']);
         //$modelAdmUsuarios->rol_id = $model->usuario_id;
         $modelAdmUsuarios->rol_id = 3;
         $modelAdmUsuarios->estado = $model->estado_id;
         $modelAdmUsuarios->save();
         $model->usuario_id = $modelAdmUsuarios->id;
         if ($model->save()) {
             $modelAdmAuditores = new AdmAuditores();
             $modelAdmAuditores->persona_id = $model->id;
             $modelAdmAuditores->save();
             $modelAdmAuditoresCoordinadores = new AdmAuditoresCoordinadores();
             $modelAdmAuditoresCoordinadores->auditor_id = $modelAdmAuditores->id;
             $modelAdmAuditoresCoordinadores->coordinador_id = 1;
             $modelAdmAuditoresCoordinadores->save();
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #2
0
 public function authenticate()
 {
     $users = AdmUsuarios::model()->findByAttributes(array('estado' => '1', 'nombre' => $this->username));
     if (empty($users->nombre)) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($users->nombre == '') {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         } else {
             if ($users->contrasena != md5($this->password)) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_id = $users->id;
                 $this->username = $users->nombre;
                 $this->setState('title', $users->nombre);
                 $this->errorCode = self::ERROR_NONE;
             }
         }
     }
     return !$this->errorCode;
 }