Esempio n. 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserAuths()
 {
     return $this->hasMany(UserAuth::className(), ['user_id' => 'id']);
 }
 /**
  * Delete an existing User model. If deletion is successful, the browser
  * will be redirected to the 'index' page.
  *
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     // delete profile and userkeys first to handle foreign key constraint
     $user = $this->findModel($id);
     // Sidash
     if ($user->id == 1) {
         return $this->redirect(['index']);
     }
     $profile = $user->profile;
     UserKey::deleteAll(['user_id' => $user->id]);
     UserAuth::deleteAll(['user_id' => $user->id]);
     $profile->delete();
     $user->delete();
     $assets = Asset::getAssets($user->id, Asset::ASSETABLE_USER, null);
     foreach ($assets as $asset) {
         $asset->delete();
     }
     return $this->redirect(['index']);
 }
 /**
  * Register a new user using client attributes and then associate userAuth
  *
  * @param \yii\authclient\BaseClient $client
  * @param \common\modules\user\models\UserAuth $userAuth
  */
 protected function registerAndLoginUser($client, $userAuth)
 {
     /** @var \common\modules\user\models\User    $user */
     /** @var \common\modules\user\models\Profile $profile */
     /** @var \common\modules\user\models\Role    $role */
     $role = Yii::$app->getModule("user")->model("Role");
     // set user and profile info
     $attributes = $client->getUserAttributes();
     $function = "setInfo" . ucfirst($client->name);
     // "setInfoFacebook()"
     list($user, $profile) = $this->{$function}($attributes);
     // calculate and double check username (in case it is already taken)
     $fallbackUsername = "******";
     $user = $this->doubleCheckUsername($user, $fallbackUsername);
     // save new models
     $user->setRegisterAttributes($role::ROLE_USER, Yii::$app->request->userIP, $user::STATUS_ACTIVE)->save(false);
     $profile->setUser($user->id)->save(false);
     $userAuth->setUser($user->id)->save(false);
     // log user in
     Yii::$app->user->login($user, Yii::$app->getModule("user")->loginDuration);
 }