public function actionLogin() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new User(); $model->scenario = 'login'; if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } return $this->render('login', ['model' => $model]); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByUsername($this->username); } return $this->_user; }
public function getPermissionsByUser($user = null) { if ($user === LuLu::getIdentity()->username) { $role = LuLu::getIdentity()->role; } else { $user = User::findOne(['username' => $user]); $role = $user->role; } return $this->getPermissionsByRole($role); // //for assignmentTable // $query = new Query(); // $query->select([ // 'p.id', // 'p.category', // 'p.name', // 'p.description', // 'p.form', // 'p.default_value', // 'p.rule', // 'p.sort_num', // 'r.role', // 'r.value' // ]); // $query->from([ // 'p' => $this->permissionTable, // 'r' => $this->relationTable, // 'a' => $this->assignmentTable // ]); // $query->where('p.id=r.permission and r.role=a.role'); // $query->andWhere([ // 'a.user' => $user // ]); // $rows = $query->all(); // return $this->convertPermissionValue($rows); }
public function getRolesByUser($username) { if ($username === LuLu::getIdentity()->username) { $role = LuLu::getIdentity()->role; } else { $user = User::findOne(['username' => $username]); $role = $user->role; } return $role; // $query = new Query(); // $query->select([ // 'r.id', // 'r.category', // 'r.name', // 'r.description', // 'r.is_system', // 'r.sort_num' // ]); // $query->from([ // 'r' => $this->roleTable, // 'a' => $this->assignmentTable // ]); // $query->where('r.id=a.role'); // $query->andWhere([ // 'a.user' => $username // ]); // $rows = $query->indexBy('id')->all(); // return $rows; }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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', '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', 'role', $this->role]); return $dataProvider; }
public function login() { if (!$this->validate()) { return false; } $user = User::findOne(['username' => $this->username]); if ($user !== null) { if ($this->validatePassword($this->password, $user->password_hash)) { \Yii::$app->user->login($user, 50000); return true; } return false; } else { return false; } }
/** * Lists all Assignment models. * @return mixed */ public function actionIndex() { $query = User::find(); $dataProvider = $this->getDataProvider($query); return $this->render('index', ['dataProvider' => $dataProvider]); }