Using the "basic" application template, what is the correct way of setting up a module login that is separate from the main site login?
For example I have an "admin" module which requires a login. I also need a user login for the main site.
I have done the following:
- Created
adminmodule usinggiitool - Created
modelsfolder within theadminmodule folder - Placed
LoginForm.phpandUser.phpwithin this folder (also updated the namespace declarations in these files) - Added
AccessControlbehaviour and login/logout actions tomodules\admin\controllers\DefaultController.php Updated
config\web.phpas follows:'modules' => [ 'admin' => [ 'class' => 'app\modules\admin\Module', ], ],Updated
app\modules\admin\Module.phpas follows:public function init() { parent::init(); Yii::$app->set('user', [ 'class' => 'yii\web\User', 'identityClass' => 'app\modules\admin\models\User', 'enableAutoLogin' => true, 'loginUrl' => ['admin/default/login'], ]); Yii::$app->set('session', [ 'class' => 'yii\web\Session', 'name' => '_adminSessionId', ]); }
The problem I am having is that if I try to access an admin page when I am not logged in, it shows the login form (this is correct). However upon logging in, it is just redirects me back to the main site. It should redirect me to the admin page I was trying to access.
In DefaultController.php, it has the following (default code):
if ($model->load(Yii::$app->request->post()) && $model->login())
return $this->goBack();
What is the correct way of doing this so I can have independent logins for the admin module and for the main site? I don't want to use the "advanced application template" as that adds some unnecessary complexity.