mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-18 01:07:37 +08:00
Modified application templates so when trying to log in when already logged in it just redirects to homepage instead of throwing exceptions
This commit is contained in:
@ -15,14 +15,9 @@ class SiteController extends Controller
|
|||||||
'class' => \yii\web\AccessControl::className(),
|
'class' => \yii\web\AccessControl::className(),
|
||||||
'rules' => [
|
'rules' => [
|
||||||
[
|
[
|
||||||
'actions' => ['error'],
|
'actions' => ['login', 'error'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'actions' => ['login'],
|
|
||||||
'allow' => true,
|
|
||||||
'roles' => ['?'],
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'actions' => ['logout', 'index'],
|
'actions' => ['logout', 'index'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
@ -49,6 +44,10 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
public function actionLogin()
|
public function actionLogin()
|
||||||
{
|
{
|
||||||
|
if (!\Yii::$app->user->isGuest) {
|
||||||
|
$this->goHome();
|
||||||
|
}
|
||||||
|
|
||||||
$model = new LoginForm();
|
$model = new LoginForm();
|
||||||
if ($model->load($_POST) && $model->login()) {
|
if ($model->load($_POST) && $model->login()) {
|
||||||
return $this->goHome();
|
return $this->goHome();
|
||||||
|
@ -17,10 +17,10 @@ class SiteController extends Controller
|
|||||||
return [
|
return [
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => \yii\web\AccessControl::className(),
|
'class' => \yii\web\AccessControl::className(),
|
||||||
'only' => ['login', 'logout', 'signup'],
|
'only' => ['logout', 'signup'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
[
|
[
|
||||||
'actions' => ['login', 'signup'],
|
'actions' => ['signup'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
'roles' => ['?'],
|
'roles' => ['?'],
|
||||||
],
|
],
|
||||||
@ -54,6 +54,10 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
public function actionLogin()
|
public function actionLogin()
|
||||||
{
|
{
|
||||||
|
if (!\Yii::$app->user->isGuest) {
|
||||||
|
$this->goHome();
|
||||||
|
}
|
||||||
|
|
||||||
$model = new LoginForm();
|
$model = new LoginForm();
|
||||||
if ($model->load($_POST) && $model->login()) {
|
if ($model->load($_POST) && $model->login()) {
|
||||||
return $this->goHome();
|
return $this->goHome();
|
||||||
|
@ -16,13 +16,8 @@ class SiteController extends Controller
|
|||||||
return [
|
return [
|
||||||
'access' => [
|
'access' => [
|
||||||
'class' => AccessControl::className(),
|
'class' => AccessControl::className(),
|
||||||
'only' => ['login', 'logout'],
|
'only' => ['logout'],
|
||||||
'rules' => [
|
'rules' => [
|
||||||
[
|
|
||||||
'actions' => ['login'],
|
|
||||||
'allow' => true,
|
|
||||||
'roles' => ['?'],
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'actions' => ['logout'],
|
'actions' => ['logout'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
@ -59,6 +54,10 @@ class SiteController extends Controller
|
|||||||
|
|
||||||
public function actionLogin()
|
public function actionLogin()
|
||||||
{
|
{
|
||||||
|
if (!\Yii::$app->user->isGuest) {
|
||||||
|
$this->goHome();
|
||||||
|
}
|
||||||
|
|
||||||
$model = new LoginForm();
|
$model = new LoginForm();
|
||||||
if ($model->load($_POST) && $model->login()) {
|
if ($model->load($_POST) && $model->login()) {
|
||||||
return $this->goBack();
|
return $this->goBack();
|
||||||
|
Reference in New Issue
Block a user