From 2916d2ec2c5b831ddb87e43503d31d0f9b6d7bb7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 22 May 2018 14:17:44 +0500 Subject: [PATCH 1/3] =the ability to set User component by configuartion --- src/AuthAction.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/AuthAction.php b/src/AuthAction.php index 38dd7a5..cf3a601 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -118,6 +118,11 @@ class AuthAction extends Action */ private $_cancelUrl; + /** + * @var instance of \yii\web\User + * user component, which might be set in different module + */ + public $user; /** * @param string $url successful URL. @@ -165,7 +170,7 @@ public function getCancelUrl() */ protected function defaultSuccessUrl() { - return Yii::$app->getUser()->getReturnUrl(); + return $this->user->getReturnUrl(); } /** @@ -174,7 +179,7 @@ protected function defaultSuccessUrl() */ protected function defaultCancelUrl() { - return Url::to(Yii::$app->getUser()->loginUrl); + return Url::to($this->user->loginUrl); } /** @@ -191,6 +196,13 @@ public function run() } $client = $collection->getClient($clientId); + if (empty($this->user)) { + $this->user = Yii::$app->getUser(); + } + if (!($this->user instanceof \yii\web\User)) { + throw new InvalidConfigException('"' . get_class($this) . '::$user" should be a instance of \yii\web\User.'); + } + return $this->auth($client); } From 6ae7f889e6bf9a4917b8d1a0f04344563ad6836b Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 May 2018 09:28:55 +0500 Subject: [PATCH 2/3] setting user component id instead of user instance --- src/AuthAction.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/AuthAction.php b/src/AuthAction.php index cf3a601..37f51cb 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -118,11 +118,19 @@ class AuthAction extends Action */ private $_cancelUrl; + /** + * @var string the ID of user component + * user component ID, which might be set in different module + */ + public $userComponentID; + /** * @var instance of \yii\web\User - * user component, which might be set in different module + * user component, which is build via userComponentID property + * if userComponentID propety not set, then default app user (Yii::$app->getUser()) component will be used */ - public $user; + private $_user; + /** * @param string $url successful URL. @@ -170,7 +178,7 @@ public function getCancelUrl() */ protected function defaultSuccessUrl() { - return $this->user->getReturnUrl(); + return $this->_user->getReturnUrl(); } /** @@ -179,7 +187,7 @@ protected function defaultSuccessUrl() */ protected function defaultCancelUrl() { - return Url::to($this->user->loginUrl); + return Url::to($this->_user->loginUrl); } /** @@ -196,10 +204,9 @@ public function run() } $client = $collection->getClient($clientId); - if (empty($this->user)) { - $this->user = Yii::$app->getUser(); - } - if (!($this->user instanceof \yii\web\User)) { + $this->_user = (!empty($this->userComponentID) && is_string($this->userComponentID)) ? Yii::createObject(["class" => $this->userComponentID]) : Yii::$app->getUser() ; + + if (!($this->_user instanceof \yii\web\User)) { throw new InvalidConfigException('"' . get_class($this) . '::$user" should be a instance of \yii\web\User.'); } From 1038e1b76dfd571db93ef833a6653f6015dfeaf8 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 May 2018 09:33:30 +0500 Subject: [PATCH 3/3] mend --- src/AuthAction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/AuthAction.php b/src/AuthAction.php index 37f51cb..52158d2 100644 --- a/src/AuthAction.php +++ b/src/AuthAction.php @@ -126,8 +126,8 @@ class AuthAction extends Action /** * @var instance of \yii\web\User - * user component, which is build via userComponentID property - * if userComponentID propety not set, then default app user (Yii::$app->getUser()) component will be used + * user component, which is build via [[userComponentID]] property + * if [[userComponentID]] propety not set, then default app user (Yii::$app->getUser()) component will be used */ private $_user;