/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::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, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]); $query->andFilterWhere(['like', 'username', $this->username]) ->andFilterWhere(['like', 'user_type', $this->user_type]) ->andFilterWhere(['like', 'auth_key', $this->auth_key]) ->andFilterWhere(['like', 'password_hash', $this->password_hash]) ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]) ->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
/** * @param $attribute * @param $params * @return bool */ public function myValidatePassword($attribute, $params) { $model = User::find()->where(['username' => $this->username])->andWhere(['status' => 1])->one(); if (!empty($model) && $model->setPassword($this->{$attribute}) == $model->password) { return true; } $this->addError($attribute, 'The username or password is error!'); }
/** * @param $attribute * @param $params * @return bool */ public function validateOriginalPassword($attribute, $params) { $model = User::find()->where(['username' => Yii::$app->session['username']])->one(); if (!empty($model) && $this->{$attribute} == $model->password) { return true; } $this->addError($attribute, 'The original password is error!'); }
/** * @return array|null|\yii\db\ActiveRecord * @throws NotFoundHttpException */ public static function findModelByUsername() { if ($username = Yii::$app->session['__username']) { if (($model = User::find()->where(['username' => $username])->one()) !== null) { return $model; } } throw new NotFoundHttpException('The requested page does not exist.'); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::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(['like', '_id', $this->_id])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'user_role', $this->user_role])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'created_at', $this->created_at])->andFilterWhere(['like', 'updated_at', $this->updated_at]); return $dataProvider; }
/** * @return \yii\web\Response */ public function actionCreate() { $model = new Comment(); $model->ip = Yii::$app->request->userIP; $model->username = Yii::$app->session['__username']; $model->user_id = User::find()->where(['username' => $model->username])->one()->id; $model->created_at = time(); $model->updated_at = time(); //$params = FilterForm::filterHtml(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['show/view', 'id' => $model->news_id]); } echo '发布失败,请重新发表评论!'; }
/** * @param $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find()->orderBy('created_at DESC'); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } if ($this->created_at !== null) { $date = strtotime($this->created_at); $query->andFilterWhere(['between', 'created_at', $date, $date + 3600 * 24]); } $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['registration_ip' => $this->registration_ip]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $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(['id' => $this->id, 'role' => $this->role, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'fname', $this->fname])->andFilterWhere(['like', 'lname', $this->lname])->andFilterWhere(['like', 'contact_no', $this->contact_no])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'company_name', $this->company_name])->andFilterWhere(['like', 'company_description', $this->company_description])->andFilterWhere(['like', 'shipping_address', $this->shipping_address])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->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 = User::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, 'role' => $this->role, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'data_nasc' => $this->data_nasc]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'nome', $this->nome])->andFilterWhere(['like', 'sexo', $this->sexo])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'endereco', $this->endereco])->andFilterWhere(['like', 'complemento', $this->complemento])->andFilterWhere(['like', 'instituicao', $this->instituicao])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'grupoacesso', $this->grupoacesso])->andFilterWhere(['like', 'cpf', $this->cpf]); return $dataProvider; }
/** * Finds user by username * * @param string $username * @return static|null */ public static function findByUsername($username) { $user = User::find()->where(['username' => $username])->asArray()->one(); if ($user) { return new static($user); } return null; /*foreach (self::$users as $user) { if (strcasecmp($user['username'], $username) === 0) { return new static($user); } } return null;*/ }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'mobile_number' => $this->mobile_number, 'mobileNumber' => $this->mobileNumber]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'addressImage', $this->addressImage]); return $dataProvider; }
/** * Authencticate or create and authenticate user * * @param \frontend\components\SteamAuth $client */ public function steamAuth($client) { $user = User::find()->where(['steamid' => $client->steamId])->one(); if (Yii::$app->user->isGuest) { if ($user) { Yii::$app->user->login($user); return $this->redirect(['site/index']); } $user = User::createSteamUser($client); if (!$user) { throw new Exception("Не получилось создать пользователя :(", 500); } return $this->redirect(['site/index']); } return $this->redirect(['site/index']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::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; } if (Yii::$app->user->identity->rol_id == '2') { $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'rol_id' => $this->rol_id, 'supervisor' => $this->supervisor, 'id_organizacion' => $this->id_organizacion, 'id_empresa' => $this->id_empresa, 'id_distrito' => $this->id_distrito])->orderBy(['username' => SORT_ASC]); } else { $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'rol_id' => '1', 'supervisor' => $this->supervisor, 'id_organizacion' => $this->id_organizacion, 'id_empresa' => $this->id_empresa, 'id_distrito' => $this->id_distrito])->orderBy(['username' => SORT_ASC]); } $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'apellido', $this->apellido])->andFilterWhere(['like', 'cedula', $this->cedula]); return $dataProvider; }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { // ...custom code here.. //unread初始值为所有接收人,添加未阅读的用户id if ($insert) { $user = User::find()->select('id')->asArray()->all(); $user = ArrayHelper::getColumn($user, 'id'); $this->unread = implode(',', $user); //将deleted初始值设置为0,防止该字段为null $this->deleted = 0; } //...custom code end return true; } else { return false; } }
public function actionLogin() { if (!Yii::$app->request->isPost) { exit('Valid Request'); } $data = Yii::$app->request->post(); $user = User::find()->where(['username' => $data['username']])->one(); $login_url = Url::toRoute(['login/index'], true); if (empty($user)) { return $this->redirect($login_url); } $password = md5(md5($data['password']) . $user->salt); if ($password != $user->password) { return $this->redirect($login_url); } $session = Yii::$app->session; if (!$session->isActive) { $session->open(); } $session['user'] = ['id' => $user->id, 'username' => $user->username]; return $this->goHome(); }
/** * Displays homepage. * * @return mixed */ public function actionIndex_old() { $model = new BraintreeForm(); $user = Yii::$app->getUser()->getIdentity(); if (!empty($user->firstname)) { $model->customer_firstName = $user->firstname; } if (!empty($user->lastname)) { $model->customer_lastName = $user->lastname; } if (!empty($user->email)) { $model->customer_email = $user->email; } if (empty($user->braintree_customer_id)) { //create braintree customer if customer id record does not exists $model->setScenario('customer'); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $customer = $model->send(); if ($customer['status']) { $user->braintree_customer_id = $customer['result']->customer->id; if ($user->save()) { //@TODO add logic to delete user on Braintree side if can not save customer id } } } } else { // else if customer id record exists $model->setScenario('creditCard'); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->customerId = $user->braintree_customer_id; if ($creditCard = $model->send()) { $model->paymentMethodToken = $creditCard['result']->creditCard->token; $model->planId = Yii::$app->get('braintree')->planId; $model->setScenario('subscription'); if ($subscription = $model->send()) { $user = Yii::$app->getUser()->getIdentity(); if (!empty($model->customer_firstName) && $model->customer_firstName != $user->firstname) { $user->firstname = $model->customer_firstName; } if (!empty($model->customer_lastName) && $model->customer_lastName != $user->lastname) { $user->lastname = $model->customer_lastName; } $checkEmail = User::find()->where(['email' => $model->customer_email])->andWhere(['not', ['id' => $user->id]])->exists(); if (!empty($model->customer_email) && $model->customer_email != $user->email && !$checkEmail) { $user->email = $model->customer_email; } $user->status = User::STATUS_PAID; if ($user->save()) { return Yii::$app->response->redirect(array('mapping')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not update user status. Please contact system administrator')); } } } } } $model->setScenario('subscription'); return $this->render('index', ['model' => $model]); }
public function getAllList() { return User::find()->all(); }
public function setEmpresa() { $this->id_empresa = ArrayHelper::getValue(User::find()->andWhere(['id' => $this->id_usuario])->asArray()->one(), 'id_empresa'); }
public function actionChecklogin() { $params = $_POST; $customer = json_decode(file_get_contents("php://input"), true); // print_r($customer); die; $username = User::find()->where(['username' => $customer['username']])->one(); if (!$username) { $this->setHeader(200); echo json_encode(array('status' => 1, 'data' => 'Username does not exist'), JSON_PRETTY_PRINT); } $pass = User::find()->where(['username' => $customer['username'], 'password' => md5($customer['password'])])->one(); if (!$pass) { $this->setHeader(200); echo json_encode(array('status' => 1, 'data' => 'password does not match'), JSON_PRETTY_PRINT); } else { Yii::$app->user->login(User::findByUsername($customer['username']), 3600 * 24 * 30); $this->setHeader(200); echo json_encode(array('user_role' => $username['user_role']), JSON_PRETTY_PRINT); } //return $this->redirect(['contact']); }
<?php echo $form->field($model, 'user_id')->hiddenInput()->label(false); ?> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'title'); ?> </div> <!--?= $form->field($model, 'file') ?--> <div class="col-md-6"> <!--?= $form->field($model, 'share_to') ?--> <?php $usr = User::find()->all(); $usrs = ArrayHelper::map($usr, function ($model) { return $model->_id->{'$id'}; }, 'username'); echo $form->field($model, 'share_to')->label('Share To')->widget(Select2::classname(), ['data' => $usrs, 'options' => ['placeholder' => 'Select User', 'id' => 'file_id'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> <div class="row"> <div class="col-md-8"> <!--?= $form->field($model, 'file')->fileInput() ?--> <?php echo $form->field($model, 'file')->widget(FileInput::classname(), ['options' => ['accept' => 'file/*'], 'pluginOptions' => ['previewFileType' => 'image', 'showUpload' => false]]); ?> </div>
public function updateUserByPsw($moblie, $newPsw) { $result = User::find()->where(array('mobile' => $moblie))->one(); $result->password = $newPsw; $result->update(); if (!$result) { return false; } return $result; }
public function actionSearchdoc() { $model = new SearchdocForm(); $user_ids = array(); $prof = new Profile(); if (Yii::$app->request->post()) { $location = $_POST['SearchdocForm']['location']; $drSpecialist = $_POST['SearchdocForm']['drSpecialist']; $model->location = $location; $model->drSpecialist = $drSpecialist; if ($location != "" && $drSpecialist != "") { $matched_id = ArrayHelper::map(Profile::find()->where(['drSpecialist' => new \MongoId($drSpecialist), 'city' => (string) $location])->all(), function ($prof) { return $prof->userId->{'$id'}; }, 'city'); foreach ($matched_id as $key => $value) { array_push($user_ids, $key); } } elseif ($location != "") { $matched_id = ArrayHelper::map(Profile::find()->where(['city' => (string) $location])->all(), function ($prof) { return $prof->userId->{'$id'}; }, 'city'); foreach ($matched_id as $key => $value) { array_push($user_ids, $key); } } elseif ($drSpecialist != "") { $matched_id = ArrayHelper::map(Profile::find()->where(['drSpecialist' => new \MongoId($drSpecialist)])->all(), function ($prof) { return $prof->userId->{'$id'}; }, 'city'); foreach ($matched_id as $key => $value) { array_push($user_ids, $key); } } else { } $doctors = User::find()->where(['_id' => $user_ids, "user_role" => '1'])->with('profile')->all(); } else { $currentUserId = Yii::$app->user->identity->_id; $session = Yii::$app->session; $location = Yii::$app->session['profile'][0]['city']; $model->location = $location; $matched_id = ArrayHelper::map(Profile::find()->where(['city' => (string) $location])->all(), function ($prof) { return $prof->userId->{'$id'}; }, 'city'); foreach ($matched_id as $key => $value) { array_push($user_ids, $key); } $doctors = User::find()->where(['_id' => $user_ids, "user_role" => '1'])->with('profile')->all(); } return $this->render('searchdoc', ['model' => $model, 'doctors' => $doctors]); }
echo $form->field($model, 'phone')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'address')->textarea(['rows' => 3]); ?> <?php echo $form->field($model, 'email')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'notes')->textarea(['rows' => 3]); ?> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\frontend\models\User::find()->all(), 'id', 'username'), ['prompt' => '']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
</div> <div class="col-md-4"> <?php echo $form->field($model, 'situacao')->dropdownList(['acordo' => 'Acordo', 'sem_acordo' => 'Sem Acordo', 'reconciliacao' => 'Reconciliação', 'redesignada' => 'Redesignada', 'processo_nao_realizados' => 'Processo Não Realizado'], ['prompt' => 'Selecione']); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'dataFim')->widget(DateControl::classname(), ['type' => DateControl::FORMAT_DATETIME, 'ajaxConversion' => false, 'value' => time(), 'options' => ['pluginOptions' => ['autoclose' => true]]]); ?> </div> </div> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'user_id')->dropDownList(ArrayHelper::map(\frontend\models\User::find()->where(['id' => Yii::$app->user->identity->id])->orderBy(['nome' => SORT_ASC])->all(), 'id', 'nome')); ?> </div> </div> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'descricao')->textArea(['maxlength' => true, 'rows' => 4, 'cols' => 30]); ?> </div> </div>
['label' => 'Event', 'url' => ['/event/index']], //['label' => 'Logs', 'url' => ['/logs/index']], //['label' => 'Migration', 'url' => ['/migration/index']], ['label' => 'Testimonials', 'url' => ['/testimonials/index']], //['label' => 'Users', 'url' => ['/user/index']], [ 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']], ]; }else if ($roles == 'alumni'){ $userid = ArrayHelper::getValue(User::find()->where(['username' => Yii::$app->user->identity->username])->one(), 'id'); $alumniid = ArrayHelper::getValue(Alumni::find()->where(['user_id' => $userid])->one(), 'id'); $menuItems =[ ['label' => 'Home', 'url' => ['/site/index']], ['label' => 'Alumni', 'url' => ['/alumni/view', 'id' => $alumniid]], ['label' => 'Event', 'url' => ['/event/index']], ['label' => 'Testimonials', 'url' => ['/testimonials/index']], [ 'label' => 'Logout (' . Yii::$app->user->identity->username . ')', 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']],
/** * Lists all User models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => User::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function checkProfileFields() { if (!Yii::$app->user->isGuest) { $userModel = User::find()->where(['id' => Yii::$app->user->id]); foreach ($this->profileFields as $field) { $userModel->andWhere(['!=', $field, '']); } return $userModel->asArray()->one(); } }
public function actionInvitations() { $datas = Invite::find()->where(['status' => 1, 'user_id' => new \MongoId(Yii::$app->user->identity->_id)])->asArray()->all(); $j = 0; foreach ($datas as $key => $value) { $doc = User::find()->where(["_id" => $datas[$j]['user_id']])->one(); $patient = User::find()->where(["_id" => $datas[$j]['patient_id']])->one(); $datas[$j]['docname'] = $doc->username; $datas[$j]['patientname'] = $patient->username; $j = $j + 1; } $doctors = User::find()->where(['user_role' => '1'])->asArray()->all(); $doctorsData = array(); $k = 0; foreach ($doctors as $key => $value) { $doctorsData[$k]['label'] = $value['username']; $doctorsData[$k]['value'] = $value['username']; $doctorsData[$k]['id'] = (string) $value['_id']; $k = $k + 1; } return $this->render('invitations', ['datas' => $datas, 'doctors' => $doctorsData]); }
public function getAnalista() { $datos = User::find()->andwhere(['rol_id' => '3'])->andwhere('user.supervisor LIKE "%' . Yii::$app->user->identity->username . '%"')->all(); return ArrayHelper::map($datos, 'id', 'username'); }