public function actionRegistration() { $model = new UserDb(); if ($model->load(Yii::$app->request->post())) { $model->data_added = date("Y-m-d H:i:s"); $model->password = md5($model->password); if ($model->save()) { return $this->render('_successfully_registration', ['first_name' => $model->first_name]); } } return $this->render('registration', ['model' => $model]); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = UserDb::find()->where(['email' => $this->email])->one(); } return $this->_user; }
public function validateEmail($attribute, $params) { if (!$this->hasErrors()) { if (empty($this->id)) { $user = UserDb::find()->where(['email' => $this->email])->one(); if ($user != null) { $this->addError($attribute, 'Пользователь с таким email уже существует!'); } } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserDb::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, 'birthday' => $this->birthday, 'paul' => $this->paul, 'data_added' => $this->data_added, 'department_id' => $this->department_id]); $query->andFilterWhere(['like', 'first_name', $this->first_name])->andFilterWhere(['like', 'last_name', $this->last_name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'phone', $this->phone])->andFilterWhere(['like', 'middle_name', $this->middle_name]); return $dataProvider; }
public function actionPassword_change() { $model = new ChangePasswordModel(); if (Yii::$app->request->isPost) { if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = UserDb::find()->where(['id' => Yii::$app->user->getId()])->one(); $user->setPassword($model->newPassword); if ($user->save()) { Yii::$app->getSession()->setFlash('success', 'New password was saved.'); return $this->render('success_change_password'); } else { \yii\helpers\VarDumper::dump($user->getErrors()); exit; } } } return $this->render('form_change_password', ['model' => $model]); }
/** * Finds the UserDb model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @param integer $department_id * @return UserDb the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $department_id) { if (($model = UserDb::findOne(['id' => $id, 'department_id' => $department_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }