Passport.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\admin\controller;
  13. use app\admin\model\admin\User as UserModel;
  14. /**
  15. * 超管后台认证
  16. * Class Passport
  17. * @package app\store\controller
  18. */
  19. class Passport extends Controller
  20. {
  21. /**
  22. * 强制验证当前访问的控制器方法method
  23. * @var array
  24. */
  25. protected $methodRules = [
  26. 'login' => 'POST',
  27. ];
  28. /**
  29. * 超管后台登录
  30. * @return array|string
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \Exception
  34. */
  35. public function login()
  36. {
  37. // 超管后台用户登录
  38. $model = new UserModel;
  39. if (($userInfo = $model->login($this->postData())) === false) {
  40. return $this->renderError($model->getError() ?: '登录失败');
  41. }
  42. return $this->renderSuccess([
  43. 'userId' => $userInfo['admin_user_id'],
  44. 'token' => $model->getToken()
  45. ], '登录成功');
  46. }
  47. /**
  48. * 退出登录
  49. */
  50. public function logout()
  51. {
  52. return $this->renderSuccess('操作成功');
  53. }
  54. }