public function actionIndex() { $this->View->title = 'Mi cuenta'; $modelAccount = new FormAccount(); $contact = Users::find()->one(Gbox::$components->user->id); $modelAccount->firstname = $contact->firstname; $modelAccount->lastname = $contact->lastname; $modelAccount->email = $contact->email; $modelAccount->username = $contact->username; if (Gbox::getRequest()->isPost() && $modelAccount->load(Gbox::getRequest()->post())) { if (!empty($modelAccount->password) && $modelAccount->password != $modelAccount->password_confirm) { $modelAccount->addError('password_confirm', 'La contraseña debe coincidir con la confirmación.'); } if ($modelAccount->validate()) { $table = new Users(); $table->firstname = $modelAccount->firstname; $table->lastname = $modelAccount->lastname; $table->email = $modelAccount->email; if (!empty($modelAccount->password) && $modelAccount->password == $modelAccount->password_confirm) { $table->password = crypt($modelAccount->password, '$2y$10$' . Gbox::getConfig()->params['salt']); } if ($table->update(Gbox::$components->user->id)) { $msg = 'Se ha editado su cuenta con éxito.'; Session::set('response', ['msg' => $msg, 'type' => 'success']); } else { Session::set('response', ['msg' => 'Ha ocurrido un error al editar su cuenta.', 'type' => 'danger']); } } else { Session::set('response', ['msg' => 'Ocurrió un error, revise los campos y vuelva a intentarlo.', 'type' => 'warning']); } } return $this->render('index', ['modelAccount' => $modelAccount]); }
/** * Finds user by username * * @param string $username * @return static|null */ public static function findByUsername($username) { $dbUser = DbUser::find()->where(["usr_id" => $username, "usr_active" => 1])->one(); if (!count($dbUser)) { return null; } // self::$users[100]=['id'=>100,'usr_id' => $dbUser->usr_id, 'usr_name' => $dbUser->usr_name]; // self::$users= [ // '100' => [ // 'id' => '100', // 'usr_id' => 'Admin', // 'usr_pass' => 'Admin', // 'authKey' => 'test100key', // 'accessToken' => '100-token', // ]]; // die(var_dump(self::$users)); // foreach (self::$users as $user) { // if (strcasecmp($user['usr_id'], $username) === 0) { // return new static($user); // } // } // return null; return new static($dbUser); // foreach (self::$users as $user) { // if (strcasecmp($user['usr_id'], $username) === 0) { // return new static($user); // } // } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Users::find()->where(['UserName' => $this->username, 'Password' => md5($this->password)])->one(); } return $this->_user; }
public function actionIndex($message = 'message') { $query = Users::find(); $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $query->count()]); $countries = $query->orderBy('username')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('index', ['countries' => $countries, 'pagination' => $pagination, 'message' => $message]); }
public function usuario_existe($attribute, $params) { $table = Users::find()->where("nombre_usuario=:nom", [":nom" => $this->nombre_usuario]); if ($table->count() != 0) { $this->addError($attribute, "El nobre de usuario seleccionado existe"); } }
public function checkEmailExists($attr) { $user = Users::find()->where('email', $this->{$attr})->one(); if ($user) { $this->addError($attr, 'El correo ya se encuentra registrado. Intente iniciar sesión o utilice otro.'); } }
public function edit($user_id) { $user = Users::find($user_id); $data = ['title' => 'Edit User ' . $user->name, 'user' => $user, 'save_url' => route('root-users-save', ['user_id' => $user->id])]; $this->title->prepend($data['title']); View::share('menu_item_active', 'users'); return view('root.users.user', $data); }
/** * Finds user by username * * @param string $username * @return static|null */ public static function findByUsername($username) { $dbUser = DbUser::find()->where(["username" => $username])->one(); if (!count($dbUser)) { return null; } return new static($dbUser); }
public function actionIndex() { $users = Users::find()->all(); /*echo "<pre>"; print_r( $users ); die();*/ return $this->render('index', ['users' => $users]); }
public static function findById($id) { $user = Users::find()->where(array('id' => $id))->asArray()->one(); if ($user) { return new static($user); } return null; }
public function delete() { if (!$this->request->is('post') && !$this->request->is('delete')) { $msg = "Users::delete can only be called with http:post or http:delete."; throw new DispatchException($msg); } Users::find($this->request->data['id'])->delete(); return $this->redirect('Users::index'); }
public function usuario_existe($attribute, $params) { $table = Users::find()->where(['nombre_usuario' => $this->nombre_usuario]); if ($table->count() != 0) { $this->addError($attribute, "El nobre de usuario seleccionado existe"); return true; } return false; }
public static function getAll() { $query = Users::find()->orderBy('id desc'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->defaultPageSize = 27; $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return ['models' => $models, 'pages' => $pages]; }
public function username_existe($attribute, $params) { //Buscar el username en la tabla $table = Users::find()->where("username=:username", [":username" => $this->username]); //Si el username existe mostrar el error if ($table->count() == 1) { $this->addError($attribute, "El usuario seleccionado existe"); } }
protected function getUser($id, &$user) { $user = null; $success = false; if ($id > 0) { $success = ($user = Users::find($id)) ? true : false; } return $success; }
/** * Updates an existing Event model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'zal' => Zal::find()->asArray()->all(), 'client' => Client::find()->asArray()->orderBy('name_client')->all(), 'users' => Users::find()->asArray()->where(['status' => 10])->orderBy('username')->all()]); } }
public function edit($user_id) { $user = Users::find($user_id); Title::prepend('Edit User'); Title::prepend($user->name); $data = ['title' => Title::renderr(' : ', true), 'user' => $user, 'save_url' => route('root-users-save', ['user_id' => $user->id])]; view()->share('menu_item_active', 'users'); return view('root.users.user', $data); }
public static function findIdentityByAccessToken($token, $type = null) { $users = Users::find()->where('active', 1)->andWhere('access_token', $token)->all(); foreach ($users as $user) { if ($user->access_token === $token) { return new static($user); } } return null; }
/** * Updates an existing Lists model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $users = Users::find()->all(); $model->users = \yii\helpers\ArrayHelper::getColumn($model->getUsers()->asArray()->all(), 'user_id'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'users' => $users]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['UserID' => $this->UserID, 'UserTypeID' => $this->UserTypeID]); $query->andFilterWhere(['like', 'FirstName', $this->FirstName])->andFilterWhere(['like', 'MiddleName', $this->MiddleName])->andFilterWhere(['like', 'LastName', $this->LastName])->andFilterWhere(['like', 'UserName', $this->UserName])->andFilterWhere(['like', 'Password', $this->Password])->andFilterWhere(['like', 'ClassSection', $this->ClassSection])->andFilterWhere(['like', 'Picture', $this->Picture])->andFilterWhere(['like', 'StudentNumber', $this->StudentNumber])->andFilterWhere(['like', 'EmployeeNumber', $this->EmployeeNumber]); return $dataProvider; }
public function login($login, $password) { $user = Users::find()->where(['login' => $login, 'password' => $password])->one(); if ($user->login) { Yii::$app->session->set('login', $login); Yii::$app->session->set('photo', $user->photo); return true; } else { return false; } }
public static function findAllForDropDownList() { $models = Users::find()->orderBy('nombre')->all(); $listData = []; foreach ($models as $model) { if (intval($model->id)) { $listData[$model->id] = $model->nombre; } } return $listData; }
public function actionForm($id = NULL) { $model = $id && Boxtypes::findOne($id) ? Boxtypes::findOne($id) : new Boxtypes(); if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { /* Uploads */ $model->pictureFile = UploadedFile::getInstance($model, 'pictureFile'); $model->buildingplanFile = UploadedFile::getInstance($model, 'buildingplanFile'); if ($model->validate()) { /* Picture */ if ($model->pictureFile) { $model->uploadPicture(); } if ($model->deleteImage && !$model->pictureFile) { $model->picture = NULL; } /* Buildingplan */ if ($model->buildingplanFile) { $model->uploadBuildingplan(); } if ($model->deleteBuildingplan && !$model->buildingplanFile) { $model->buildingplan = NULL; } /* Save the model */ $model->save(false); /* Unlink all previous entries */ $model->unlinkAll('boxtypeEntrances', true); /* Save all the selected visit methods */ if (isset($_POST['Boxtypes']['entrances'])) { foreach (Yii::$app->request->post('Boxtypes')['entrances'] as $entrance) { $entrancesModel = new BoxtypeEntrances(); $entrancesModel->entrance_index = $entrance; if ($entrance == Boxtypes::BOX_ENTRANCES_OTHER) { $entrancesModel->other = Yii::$app->request->post('Boxtypes')['entrance_other']; } $entrancesModel->link('boxtypes', $model); $entrancesModel->save(); } } return $this->redirect(Url::toRoute('boxtypes/detail/' . $model->id)); } else { /* Save checked entrances */ if (isset($_POST['Boxtypes']['entrances'])) { foreach (Yii::$app->request->post('Boxtypes')['entrances'] as $entrance) { $model->checked_entrances[$entrance] = $entrance != Boxtypes::BOX_ENTRANCES_OTHER ? true : Yii::$app->request->post('Boxtypes')['entrance_other']; } } } } return $this->render('form', ['model' => $model, 'users' => Users::find()->select(['id', new \yii\db\Expression("CONCAT(username, ' (', fullname, ')') as username")])->all()]); }
public function ajaxShow($id) { if (!Groups::check('site', Groups::getAuth('site', 'update_full_admin'))) { return; } $user = Users::find('id', $id); $this->set('url', Router::url('admin:user.update', ['id' => $id])); $this->set('user', $user); $this->set('groups', Groups::findAll()); $this->render('admin/users_spec'); }
public function validateIfExists($attribute, $params) { if ($this->hasErrors()) { return false; } if ($attribute == self::FIELD_LOGIN && $this->login) { if (Users::find()->where([Users::FIELD_LOGIN => $this->login])->exists()) { $this->addError($attribute, 'User with this login already exists'); } } return true; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['userId' => $this->userId, 'personalCode' => $this->personalCode, 'phone' => $this->phone, 'active' => $this->active, 'isDead' => $this->isDead]); $query->andFilterWhere(['like', 'firstName', $this->firstName])->andFilterWhere(['like', 'lastName', $this->lastName])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'lang', $this->lang]); return $dataProvider; }
public function search($search) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $search = ArrayHelper::htmlEncode($search); if ($search['keyword'] != '') { $query->andFilterWhere(['like', $search['in_keyword'], $search['keyword']]); } if ($search['status'] != -1) { $query->andFilterWhere(['status' => $search['status']]); } return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => self::PAGE_COUNT]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['user_id' => $this->user_id, 'score' => $this->score, 'create_time' => $this->create_time]); $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'idcard', $this->idcard])->andFilterWhere(['like', 'mobile', $this->mobile]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Users::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'activate' => $this->activate, 'role' => $this->role]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'authKey', $this->authKey])->andFilterWhere(['like', 'accessToken', $this->accessToken])->andFilterWhere(['like', 'verification_code', $this->verification_code]); return $dataProvider; }