SiteController.php 2.1 KB

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