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.

79 lines
2.5 KiB

  1. <?php
  2. namespace api\controllers;
  3. /*
  4. * The MIT License
  5. *
  6. * Copyright 2019 Blobt.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. use common\models\ars\Config;
  27. use common\models\User;
  28. use yii\base\NotSupportedException;
  29. use yii\filters\auth\HttpBearerAuth;
  30. use yii\helpers\ArrayHelper;
  31. use yii\helpers\Url;
  32. use yii\rest\ActiveController;
  33. use Yii;
  34. class UserController extends ActiveController
  35. {
  36. public $modelClass = 'common\models\User';
  37. public function actions()
  38. {
  39. $actions = parent::actions();
  40. unset($actions['index']);
  41. unset($actions['create']);
  42. }
  43. public function actionIndex()
  44. {
  45. $key = $param = base64_encode(1 + date('Y')
  46. + date('m') - date('d') - date('h'));
  47. $data = [];
  48. Yii::$app->userLogic->createUser($data, $key);
  49. $response = Yii::$app->getResponse();
  50. $response->setStatusCode(201);
  51. return ['status' => true];
  52. }
  53. public function actionCreate()
  54. {
  55. $key = Yii::$app->request->post('key');
  56. $data = \Yii::$app->request->post('data');
  57. Yii::$app->userLogic->createUser($data, $key);
  58. $response = Yii::$app->getResponse();
  59. $response->setStatusCode(201);
  60. return ['status' => true];
  61. }
  62. public function actionMenu()
  63. {
  64. $key = Yii::$app->request->get('key');
  65. // $key = sha1(date('Y') - date('m') + date('d') + 1);
  66. if (Yii::$app->userLogic->login($key)) {
  67. return Yii::$app->userLogic->getUserMenu();
  68. }
  69. }
  70. }