我有一个在Yii2高级模板的代码,这里我想为用户和管理员的后端的前端单一的登录页。一旦我已经从前端登录,然后,如果那是一个管理员,那么我想重定向到后台主页的登录,而不是登录在前端,也如果这是一个用户,然后我想重定向在前端主页。
在这里,我的问题是管理员用户,我已经重定向到后端索引页面,但我需要在后端再次登录。此外,如果我使用前台管理,该帐户仍然保留。
我的前台siteController.php:
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post())){
$userDetails = User::findByUsername($model->username);
if($userDetails->username == 'admin' && $model->login()) {
return $this->redirect('http://localhost/yiiadvanced/backend/web/index.php');
} else {
$model->login();
return $this->redirect(array('/site/custom'));
}
} else {
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
}管理数据和用户数据在同一个表中。
任何人,请给出这个问题的解决方案,
提前谢谢。
发布于 2018-09-18 12:43:00
“需要后台重新登录”,为了区分前端和后端用户,您可以在配置中更改前后端名称不同的会话名称
'session' => [
// this is the name of the session cookie used for login on the backend
'name' => 'advanced-frontend',
],https://stackoverflow.com/questions/52365386
复制相似问题