You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace kcadmin\controllers;
  3. use Yii;
  4. use yii\web\Controller;
  5. use yii\filters\VerbFilter;
  6. use yii\filters\AccessControl;
  7. use common\models\LoginForm;
  8. use common\models\CategorySearch;
  9. /**
  10. * Site controller
  11. */
  12. class SiteController extends Controller {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function behaviors() {
  17. return [
  18. 'access' => [
  19. 'class' => AccessControl::className(),
  20. 'rules' => [
  21. [
  22. 'actions' => ['login', 'error', 'test'],
  23. 'allow' => true,
  24. ],
  25. [
  26. 'actions' => ['logout', 'index'],
  27. 'allow' => true,
  28. 'roles' => ['@'],
  29. ],
  30. ],
  31. ],
  32. 'verbs' => [
  33. 'class' => VerbFilter::className(),
  34. 'actions' => [
  35. // 'logout' => ['post'],
  36. ],
  37. ],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function actions() {
  44. return [
  45. 'error' => [
  46. 'class' => 'yii\web\ErrorAction',
  47. ],
  48. ];
  49. }
  50. /**
  51. * Displays homepage.
  52. *
  53. * @return string
  54. */
  55. public function actionIndex() {
  56. return $this->render('index');
  57. }
  58. /**
  59. * Login action.
  60. *
  61. * @return string
  62. */
  63. public function actionLogin() {
  64. $this->layout = 'base';
  65. if (!Yii::$app->user->isGuest) {
  66. return $this->goHome();
  67. }
  68. $model = new LoginForm();
  69. if ($model->load(Yii::$app->request->post()) && $model->login()) {
  70. return $this->goBack();
  71. } else {
  72. $model->password = '';
  73. return $this->render('login', [
  74. 'model' => $model,
  75. ]);
  76. }
  77. }
  78. /**
  79. * Logout action.
  80. *
  81. * @return string
  82. */
  83. public function actionLogout() {
  84. Yii::$app->user->logout();
  85. return $this->goHome();
  86. }
  87. public function actionTest() {
  88. $searchModel = new CategorySearch();
  89. return $this->render('test', [
  90. 'name' => 'blobt',
  91. 'model' => $searchModel
  92. ]);
  93. }
  94. }