/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User_group::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, 'tenant_id' => $this->tenant_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionLogin() { $params = $_REQUEST; $tenantName = ''; $tenant = new Tenant(); $username = ''; $user = ''; if (isset($params['username']) && isset($params['tenantName']) && isset($params['token'])) { $username = $params['username']; $user = User::findByUsername($username); //User::find()->where(['username' => $username]); $tenantName = $params['tenantName']; $tenant = Tenant::find()->where(['name' => $tenantName]); $token = $params['token']; $code = "fromblakpearl4todaduubyantoniochiriaco"; $decoded_parameters = $username . $tenantName . $code; //$encoded_parameters = crypt($decoded_parameters, '$2y$15$R.gJb2U2N.FmZ4hPp1y2CN$'); //'$6$sawhmo1pMjf7$'); //echo $token; //echo " "; //echo $encoded_parameters; //exit; if (crypt($decoded_parameters, $token) != $token) { //($token != $encoded_parameters) throw new NotFoundHttpException('Le credenziali d\'accesso non sono corrette!'); } if ($tenant->exists() && $user != null) { if ($tenant->scalar() != $user->tenant_id) { throw new NotFoundHttpException('Le credenziali d\'accesso non sono corrette!'); } else { Yii::$app->user->login($user); return $this->goHome(); } } if (!$tenant->exists()) { $tenant = new Tenant(); $tenant->autologin = true; $tenant->name = $tenantName; $tenant->username = $username; $tenant->save(); //$tenant = Tenant::find()->where(['name' => $tenantName]); } else { if ($user == null) { $user = new User(); $user->username = $username; $user->email = '*****@*****.**'; $user->tenant_id = $tenant->scalar(); $user->setPassword('admin'); $user->generateAuthKey(); $user->save(); // Inserimento dell'utente neli'ultimo gruppo del tenant /*$group = User_group::find()->orderBy('id desc')->one(); $user_to_user_group = new User_to_user_group(); $user_to_user_group->user_id = $user->id; $user_to_user_group->user_group_id = $group['id']; $user_to_user_group->save(); */ $group = User_group::find()->where(['name' => 'Standard', 'tenant_id' => $user->tenant_id])->one(); $user_to_user_group = new User_to_user_group(); $user_to_user_group->user_id = $user->id; $user_to_user_group->user_group_id = $group['id']; $user_to_user_group->save(); Yii::$app->user->login($user); return $this->goHome(); } } return $this->goHome(); } else { throw new NotFoundHttpException('Le credenziali d\'accesso non sono corrette!'); } /* $model = new LoginForm(); if ($model->load(Yii::$app->request->post()) && $model->login()) { return $this->goBack(); } else { return $this->render('login', [ 'model' => $model, ]); }*/ }
public static function getGroups() { $queryGruppi = User_group::find()->asArray()->all(); $arrayGruppi = ArrayHelper::map($queryGruppi, 'id', 'name'); return $arrayGruppi; }