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.

125 lines
2.8 KiB

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