示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Tenant::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Finds the Tenant model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Tenant the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Tenant::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#3
0
 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,
                 ]);
             }*/
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTenant()
 {
     return $this->hasOne(Tenant::className(), ['id' => 'tenant_id']);
 }