LoginController.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | whitef快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/whitef
  8. // | github下载:https://github.com/likeshop-github/whitef
  9. // | 访问官网:https://www.whitef.cn
  10. // | whitef团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: whitefTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\workerapi\controller;
  15. use app\workerapi\controller\BaseApiController;
  16. use app\workerapi\logic\LoginLogic;
  17. use app\workerapi\validate\LoginAccountValidate;
  18. use app\workerapi\validate\RegisterValidate;
  19. /**
  20. * 登录注册
  21. * Class LoginController
  22. * @package app\api\controller
  23. */
  24. class LoginController extends BaseApiController
  25. {
  26. public array $notNeedLogin = ['register', 'account', 'logout'];
  27. /**
  28. * @notes 注册账号
  29. * @return \think\response\Json
  30. * @author 段誉
  31. * @date 2022/9/7 15:38
  32. */
  33. public function register()
  34. {
  35. $params = (new RegisterValidate())->post()->goCheck('register');
  36. $res = LoginLogic::confirmMobile($params);
  37. if(!$res){
  38. return $this->fail(LoginLogic::getError());
  39. }
  40. $result = LoginLogic::register($params);
  41. if (true === $result) {
  42. return $this->success('注册成功', [], 1, 1);
  43. }
  44. return $this->fail(LoginLogic::getError());
  45. }
  46. /**
  47. * @notes 账号密码/手机号密码/手机号验证码登录
  48. * @return \think\response\Json
  49. * @author 段誉
  50. * @date 2022/9/16 10:42
  51. */
  52. public function account()
  53. {
  54. $params = (new LoginAccountValidate())->post()->goCheck();
  55. $result = LoginLogic::login($params);
  56. if (false === $result) {
  57. return $this->fail(LoginLogic::getError());
  58. }
  59. return $this->data($result);
  60. }
  61. /**
  62. * @notes 退出登录
  63. * @return \think\response\Json
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @author 段誉
  68. * @date 2022/9/16 10:42
  69. */
  70. public function logout()
  71. {
  72. LoginLogic::logout($this->userInfo);
  73. return $this->success();
  74. }
  75. }