Passport.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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 think\response\Json;
  14. use app\admin\service\admin\User as AdminUserService;
  15. use app\admin\model\admin\User as UserModel;
  16. /**
  17. * 超管后台认证
  18. * Class Passport
  19. * @package app\store\controller
  20. */
  21. class Passport extends Controller
  22. {
  23. /**
  24. * 强制验证当前访问的控制器方法method
  25. * @var array
  26. */
  27. protected array $methodRules = [
  28. 'login' => 'POST',
  29. ];
  30. /**
  31. * 超管后台登录
  32. * @return Json
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. * @throws \Exception
  36. */
  37. public function login(): Json
  38. {
  39. // 超管后台用户登录
  40. $model = new UserModel;
  41. if (($userInfo = $model->login($this->postData())) === false) {
  42. return $this->renderError($model->getError() ?: '登录失败');
  43. }
  44. return $this->renderSuccess([
  45. 'userId' => $userInfo['admin_user_id'],
  46. 'token' => $model->getToken()
  47. ], '登录成功');
  48. }
  49. /**
  50. * 退出登录
  51. * @return Json
  52. */
  53. public function logout(): Json
  54. {
  55. AdminUserService::logout();
  56. return $this->renderSuccess('操作成功');
  57. }
  58. }