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.

56 lines
1.2 KiB

  1. <?php
  2. namespace api\controllers;
  3. use api\logic\Login;
  4. use common\models\User;
  5. use yii\filters\auth\HttpBearerAuth;
  6. use yii\helpers\ArrayHelper;
  7. use yii\rest\ActiveController;
  8. use Yii;
  9. class UserController extends ActiveController
  10. {
  11. public $modelClass = 'common\models\User';
  12. public function behaviors()
  13. {
  14. return ArrayHelper::merge(parent::behaviors(), [
  15. 'authenticatior' => [
  16. 'class' => HttpBearerAuth::className(),
  17. 'except' => ['token'],
  18. ]
  19. ]);
  20. }
  21. public function actions()
  22. {
  23. $action = parent::actions();
  24. unset($action['delete']);
  25. unset($action['create']);
  26. unset($action['update']);
  27. unset($action['index']);
  28. $action['options'] = [
  29. 'class' => 'yii\rest\OptionsAction',
  30. 'collectionOptions' => ['PUT', 'GET', 'OPTIONS']
  31. ];
  32. return $action;
  33. }
  34. public function actionIndex()
  35. {
  36. return Yii::$app->user->identity;
  37. }
  38. /**
  39. * @return string
  40. * @throws \yii\base\Exception
  41. * @throws \yii\web\NotFoundHttpException
  42. * @throws \yii\web\ServerErrorHttpException
  43. */
  44. public function actionToken()
  45. {
  46. return Login::wxLogin();
  47. }
  48. }