/** * @return \yii\db\ActiveQuery */ public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); }
/** * @param string $email * @param string $username * @return mixed */ public function create($email, $username) { $model = User::find()->where(['email' => $email])->one(); if (!$model) { $model = new User(); $model->email = $email; $model->username = $username; if ($model->save()) { return $model; } return null; } return $model; }
/** * @param integer $id * @param string $email * @return mixed */ public function actionAddAuth0User($id, $email, $username, $auth0UserId, $role = 'user') { Yii::$app->auth0->updateAppMetadata($auth0UserId, Yii::$app->auth0->getNewAppMetadata($auth0UserId, Tenant::findOne($id)->name, $role)); $user = User::create($email, $username); TenantUser::create(Tenant::findOne($id), $user); }