/**
  * Creates a new Usuario model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Usuario();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 2
0
 /**
  * borrar usuario
  * @param type $id
  * @return type
  */
 public function actionBorrar($id)
 {
     $modelo = new Usuario();
     if ($modelo->load(Yii::$app->request->post())) {
     } else {
         $usuario = $modelo->findOne(['id' => $id]);
         return $this->render("editar", ['model' => $usuario]);
     }
     return $this->render("editar", ['model' => $modelo]);
 }
 /**
  * Creates a new Usuario model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $departamento = ArrayHelper::map(Departamento::find()->all(), 'id', 'nome');
     $model = new Usuario();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'departamento_lista' => $departamento]);
     }
 }
Ejemplo n.º 4
0
 /**
  * Deletes an existing Usuario model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionLogin()
 {
     if (!\Yii::$app->user->isGuest) {
         return $this->goHome();
     }
     $model = new Usuario();
     if ($model->load(Yii::$app->request->post()) && $model->login()) {
         Yii::$app->user->login($model, 3600 * 24 * 30);
         return $this->goHome();
     }
     return $this->render('login', ['model' => $model]);
 }
Ejemplo n.º 5
0
 /**
  * Creates a new Usuario model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $user = new Usuario();
     $inst = new Institucion();
     $cont = new Contacto();
     $dir = new Direccion();
     $repr = new Representante();
     $modelsConocimientos = [new Conocimiento()];
     $institucion = ArrayHelper::map(Institucion::find()->all(), 'id_institucion', 'nombre');
     if ($user->load(Yii::$app->request->post()) && $cont->load(Yii::$app->request->post()) && $dir->load(Yii::$app->request->post()) && $repr->load(Yii::$app->request->post())) {
         $modelsConocimientos = Model::createMultiple(Conocimiento::classname());
         Model::loadMultiple($modelsConocimientos, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsConocimientos), ActiveForm::validate($user));
         }
         // validate all models
         $valid = $user->validate();
         $valid = Model::validateMultiple($modelsConocimientos) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $user->save(false)) {
                     foreach ($modelsConocimientos as $modelConocimientos) {
                         $modelConocimientos->Usuarioid_usuario = $user->id_usuario;
                         if (!($flag = $modelConocimientos->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $user->id_usuario]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         $user->save();
         $cont->Usuarioid_usuario = $user->id_usuario;
         $dir->Usuarioid_usuario = $user->id_usuario;
         $repr->Usuarioid_usuario = $user->id_usuario;
         if ($repr->save() && $cont->save() && $dir->save()) {
             return $this->redirect(['view', 'id' => $user->id_usuario]);
         } else {
             return $this->redirect(['index', 'id' => $user->id_usuario]);
         }
     } else {
         return $this->render('create', ['user' => $user, 'cont' => $cont, 'dir' => $dir, 'repr' => $repr, 'institucion' => $institucion, 'modelsConocimientos' => empty($modelsConocimientos) ? [new Conocimiento()] : $modelsConocimientos]);
     }
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Usuario model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Usuario();
     $model->usua_habilitado = true;
     if ($model->load(Yii::$app->request->post())) {
         $model->usua_imagem = UploadedFile::getInstance($model, 'usua_imagem');
         if ($model->save()) {
             Yii::$app->session->setFlash('success', 'Usuário cadastrado com sucesso!');
             return $this->redirect(['index']);
         }
         //return $this->redirect(['view', 'id' => $model->usua_codigo]);
     }
     return $this->render('create', ['model' => $model]);
 }
Ejemplo n.º 7
0
 /**
  * Creates a new EmpresaPyme model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $empresa = new EmpresaPyme();
     $servicio = new EmpContrataServ();
     $usuario = new Usuario();
     if ($empresa->load(Yii::$app->request->post()) && $servicio->load(Yii::$app->request->post()) && $usuario->load(Yii::$app->request->post())) {
         $servicio->emp_rut = $empresa->emp_rut;
         $servicio->serv_fecha_ini = date('Y-m-d');
         $usuario->emp_rut = $empresa->emp_rut;
         $usuario->usu_contraseña = "1234";
         $usuario->usu_tipo = 1;
         if ($empresa->save() && $servicio->save() && $usuario->save()) {
             return $this->redirect(['view', 'id' => $empresa->emp_rut]);
         }
     } else {
         return $this->render('create', ['empresa' => $empresa, 'servicio' => $servicio, 'usuario' => $usuario]);
     }
 }
Ejemplo n.º 8
0
 public function actionCreate()
 {
     PermisosController::permisoAdministrador();
     $model = new Usuario();
     $msg = null;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $table = new UsuarioTabla();
             $table->NOMBRE_USUARIO = $model->NOMBRE_USUARIO;
             $table->ID_DEPARTAMENTO = $model->id_departamento;
             $table->ID_ROL = $model->id_rol;
             $table->EMAIL = $model->EMAIL;
             $table->PASSWORD = sha1($model->password);
             $table->ID_USUARIO = null;
             $table->generateAuthKey();
             $table->generateAccessToken();
             if ($table->insert()) {
                 $msg = '<div class="alert alert-success" role="alert">Registro insertado correctamente</div>';
                 $model = new Usuario();
             } else {
                 $msg = '<div class="alert alert-danger" role="alert">Error al insertar registro</div>';
             }
         }
     } else {
         $model->getErrors();
     }
     return $this->render("Create", ["model" => $model, "msg" => $msg]);
 }