Skip to content

Commit

Permalink
Fixes #218: Allow configuring user component in AuthAction
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark authored Oct 18, 2018
1 parent 463954a commit bebf74b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 authclient extension Change Log
2.1.8 under development
-----------------------

- Enh #218: Allow configuring user component in `AuthAction` (samdark, lab362)
- Bug #237: Fix redirect from LinkedIn if user refused to authorize permissions request (jakim)


Expand Down
20 changes: 18 additions & 2 deletions src/AuthAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\NotSupportedException;
use yii\di\Instance;
use yii\helpers\Url;
use yii\web\Response;
use yii\web\HttpException;
use yii\web\NotFoundHttpException;
use Yii;
use yii\web\User;

/**
* AuthAction performs authentication via different auth clients.
Expand Down Expand Up @@ -109,6 +111,12 @@ class AuthAction extends Action
*/
public $redirectView;

/**
* @var User|array|string the User object or the application component ID of the user component.
* @since 2.1.8
*/
public $user = 'user';

/**
* @var string the redirect url after successful authorization.
*/
Expand All @@ -118,6 +126,14 @@ class AuthAction extends Action
*/
private $_cancelUrl;

/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->user = Instance::ensure($this->user, User::className());
}

/**
* @param string $url successful URL.
Expand Down Expand Up @@ -165,7 +181,7 @@ public function getCancelUrl()
*/
protected function defaultSuccessUrl()
{
return Yii::$app->getUser()->getReturnUrl();
return $this->user->getReturnUrl();
}

/**
Expand All @@ -174,7 +190,7 @@ protected function defaultSuccessUrl()
*/
protected function defaultCancelUrl()
{
return Url::to(Yii::$app->getUser()->loginUrl);
return Url::to($this->user->loginUrl);
}

/**
Expand Down

0 comments on commit bebf74b

Please sign in to comment.