public function beforeAction($action) { $auth_key = Yii::$app->request->getQueryParam('auth_key'); $client_user = null; if ($auth_key !== null) { $client_user = ClientUsers::findOne(['auth_key' => $auth_key]); } if (!$client_user instanceof ClientUsers) { throw new HttpException(403, 'You are not allowed to perform this action'); } else { $action->controller->client_user = $client_user; return true; } }
public function login() { $client_user = ClientUsers::findOne(['email' => $this->email]); if ($client_user instanceof ClientUsers) { if (!Yii::$app->getSecurity()->validatePassword($this->password, $client_user->password)) { $this->addError('password', 'Your password is invalid'); return false; } else { $this->auth_key = $client_user->auth_key; return true; } } else { return false; } }
public function clientBeacons($client_user_id = null) { $query = Beacons::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } if ($client_user_id !== null) { $user = ClientUsers::findOne(['id' => $client_user_id]); $query->joinWith(['clientBeacons' => function (ActiveQuery $query) use($user) { $query->andFilterWhere(['client_id' => $user->id]); }]); } $query->andFilterWhere(['id' => $this->id, 'minor' => $this->minor, 'major' => $this->major]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'uuid', $this->uuid]); return $dataProvider; }