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.

83 lines
1.6 KiB

  1. <?php
  2. namespace backend\controllers;
  3. use Yii;
  4. use yii\base\NotSupportedException;
  5. use yii\web\Controller;
  6. use yii\filters\VerbFilter;
  7. use yii\filters\AccessControl;
  8. use common\models\LoginForm;
  9. use common\models\CategorySearch;
  10. use yii\web\Cookie;
  11. use yii\web\ForbiddenHttpException;
  12. use yii\web\NotAcceptableHttpException;
  13. use yii\web\NotFoundHttpException;
  14. /**
  15. * Site controller
  16. */
  17. class SiteController extends Controller
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function actions()
  23. {
  24. return [
  25. 'error' => [
  26. 'class' => 'yii\web\ErrorAction',
  27. ],
  28. 'upload' => [
  29. 'class' => 'iron\actions\UploadAction',
  30. ]
  31. ];
  32. }
  33. /**
  34. * Displays homepage.
  35. *
  36. * @return string
  37. */
  38. public function actionIndex()
  39. {
  40. return $this->render('index');
  41. }
  42. public function actionLogin()
  43. {
  44. if (!Yii::$app->user->isGuest) {
  45. return $this->goHome();
  46. }
  47. $key = Yii::$app->request->get('key');
  48. if (Yii::$app->userLogic->login($key)) {
  49. return $this->goBack();
  50. } else {
  51. throw new ForbiddenHttpException('身份验证失败,请重新进去');
  52. }
  53. }
  54. /**
  55. * Logout action.
  56. *
  57. * @return string
  58. */
  59. public function actionLogout()
  60. {
  61. Yii::$app->user->logout();
  62. return $this->goHome();
  63. }
  64. public function actionTest()
  65. {
  66. $searchModel = new CategorySearch();
  67. return $this->render('test', [
  68. 'name' => 'blobt',
  69. 'model' => $searchModel
  70. ]);
  71. }
  72. }