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.

106 lines
2.2 KiB

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