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.

119 lines
2.5 KiB

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