/** * Finds user by [[username]] * * @return User|null */ protected function getUser() { if ($this->_user === null) { $this->_user = Usuarios::find()->where(['correo' => $this->correo])->activo()->one(); } return $this->_user; }
public function email_existe($attribute) { if (Usuarios::find()->where(['correo' => $this->correo])->exists()) { $this->addError($attribute, "El email seleccionado existe"); return true; } else { return false; } }
/** * @param $id * @return ActiveDataProvider */ public function buscar($id) { $query = Usuarios::find(); $query->with(['empresas']); $query->where(['idusuario' => $id]); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false, 'pagination' => false]); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Usuarios::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['idusuario' => SORT_DESC, 'fechacreado' => SORT_DESC]], 'pagination' => ['pageSize' => 15]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['idusuario' => $this->idusuario, 'votos' => $this->votos, 'fechacreado' => $this->fechacreado, 'fechaactualizado' => $this->fechaactualizado, 'status' => $this->status]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'correo', $this->correo])->andFilterWhere(['like', 'telefono', $this->telefono])->andFilterWhere(['like', 'foto', $this->foto])->andFilterWhere(['like', 'tipo', $this->tipo])->andFilterWhere(['like', 'estado', $this->estado])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'clave', $this->clave])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'clave_hash', $this->clave_hash])->andFilterWhere(['like', 'clave_reset_token', $this->clave_reset_token]); return $dataProvider; }
/** * Updates an existing Usuarios model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionActualizar($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { //$model->setPassword($model->clave_hash); //$model->generateAuthKey(); //$model->tipo = Usuarios::ES_VISITA; $model->save(); $archivo_tmp_original = Yii::getAlias('@backend') . '/web/' . str_replace(".", '-original.', $model->imagen_nombre); $archivo_tmp = Yii::getAlias('@backend') . '/web/' . $model->imagen_nombre; $imagen_nombre = $model->idusuario . '_' . uniqid() . '.png'; $ruta = Yii::getAlias('@libreria') . '/imagenes/usuarios/' . $imagen_nombre; $data = base64_decode($model->imagen_data); file_put_contents($ruta, $data); if (file_exists($ruta)) { $imgModel = Usuarios::find()->where(['idusuario' => $model->idusuario])->one(); $imgModel->foto = $imagen_nombre; $imgModel->save(); if (file_exists($archivo_tmp)) { unlink($archivo_tmp); unlink($archivo_tmp_original); } } return $this->redirect(['detalle', 'id' => $model->idusuario]); } else { return $this->render('actualizar', ['model' => $model]); } }
/** * Retorna listado de todos los usuarios id y nombre * Para usar con select * @return array */ public function listadoUsuarios() { $listado = Usuarios::find()->all(); return ArrayHelper::map($listado, 'idusuario', 'nombre'); }
/** * Crea un usuario temporal con el fin de poder enviar mensajes a un propietario de articulo * @param $nombre * @param $correo * @param $telefono * @return array|Usuarios|null|ActiveRecord */ public function crearUsuarioTemporal($nombre, $correo, $telefono) { $usuario = Usuarios::find()->where('correo = :correo', [':correo' => $correo])->one(); if (empty($usuario)) { $user = new Usuarios(); $user->scenario = self::ESCENARIO_CREAR_CUENTA_TEMPORAL; $user->nombre = $nombre; $user->correo = $correo; $user->telefono = $telefono; $user->clave = self::CLAVE_TEMPORAL; $user->setPassword($this->clave); $user->tipo = Usuarios::ES_PARTICULAR; $user->estado = Usuarios::ESTA_TEMPORAL; $user->generateAuthKey(); if ($user->save()) { Autorizacion::asignarRolParticular($user->idusuario); $config = new Configuracion(); $config->asignarConfiguracionUsuario($user->idusuario, Configuracion::ESCENARIO_WEB); $usuario = $user; } } return $usuario; }
/** * Finds not active users by account activation token. Will return null if user not found or token expired * @param string $token account activation token * @return Usuarios|null */ public static function buscarUsuarioActivacionToken($token) { $expire = \Yii::$app->params['user.accountActivationTokenExpire']; $parts = explode('_', $token); $timestamp = (int) end($parts); if ($timestamp + $expire < time()) { return null; // token expired } return Usuarios::find()->where(['activacion_token' => $token])->noActivo()->one(); }