Created
January 18, 2018 22:54
-
-
Save calcio/6a5d45ceb33fde835ddbf64bf2c789b9 to your computer and use it in GitHub Desktop.
Vitrine - Module Admin - DefaultController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\modules\admin\controllers; | |
use Yii; | |
use yii\web\Controller; | |
use yii\filters\VerbFilter; | |
use yii\filters\AccessControl; | |
use app\modules\admin\models\LoginForm; | |
/** | |
* Default controller for the `admin` module | |
*/ | |
class DefaultController extends Controller | |
{ | |
public function behaviors() | |
{ | |
return [ | |
'access' => [ | |
'class' => AccessControl::className(), | |
'only' => ['index', 'logout', 'dashboard'], | |
'rules' => [ | |
[ | |
'actions' => ['index'], | |
'allow' => true, | |
'roles' => ['?'], | |
], | |
[ | |
'actions' => ['logout', 'dashboard'], | |
'allow' => true, | |
'roles' => ['@'], | |
], | |
], | |
], | |
'verbs' => [ | |
'class' => VerbFilter::className(), | |
'actions' => [ | |
'logout' => ['post'], | |
], | |
], | |
]; | |
} | |
/** | |
* Renders the index view for the module | |
* @return string | |
*/ | |
public function actionIndex() | |
{ | |
if (!Yii::$app->user->isGuest) { | |
return $this->render('dashboard'); | |
} | |
$model = new LoginForm(); | |
if ($model->load(Yii::$app->request->post()) && $model->login()) { | |
return $this->render('dashboard'); | |
} | |
return $this->render('index', ['model' => $model]); | |
} | |
public function actionDashboard() | |
{ | |
return $this->render('dashboard'); | |
} | |
public function actionLogout() | |
{ | |
Yii::$app->user->logout(); | |
return $this->redirect(['default/index']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment