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.

108 lines
2.3 KiB

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