Login.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shopapi\controller;
  11. use app\model\system\User as UserModel;
  12. use app\model\web\Config as ConfigModel;
  13. class Login extends BaseApi
  14. {
  15. /**
  16. * 登录方法
  17. */
  18. public function login()
  19. {
  20. if (empty($this->params[ "username" ])) return $this->response($this->error([], "商家账号不能为空!"));
  21. if (empty($this->params[ "password" ])) return $this->response($this->error([], "密码不可为空!"));
  22. $config_model = new ConfigModel();
  23. $config_info = $config_model->getCaptchaConfig();
  24. $config = $config_info[ 'data' ][ 'value' ];
  25. $shop_login = $config[ "shop_login" ] ?? 0;
  26. if ($shop_login == 1) {
  27. // 校验验证码
  28. $captcha = new Captcha();
  29. $check_res = $captcha->checkCaptcha();
  30. if ($check_res[ 'code' ] < 0) return $this->response($check_res);
  31. }
  32. // 登录
  33. $login = new UserModel();
  34. $res = $login->uniAppLogin($this->params[ 'username' ], $this->params[ "password" ], $this->app_module);
  35. //生成access_token
  36. if ($res[ 'code' ] >= 0) {
  37. $token = $this->createToken($res[ 'data' ]);
  38. return $this->response($this->success([ 'token' => $token, 'site_id' => $res[ 'data' ][ 'site_id' ] ]));
  39. }
  40. return $this->response($res);
  41. }
  42. /**
  43. * 修改密码
  44. * */
  45. public function modifyPassword()
  46. {
  47. if (empty($this->params[ "old_pass" ])) return $this->response($this->error([], "旧密码不能为空!"));
  48. if (empty($this->params[ "new_pass" ])) return $this->response($this->error([], "新密码不能为空!"));
  49. $token = $this->checkToken();
  50. if ($token[ 'code' ] < 0) return $this->response($token);
  51. $user_model = new UserModel();
  52. $condition = [
  53. ['uid','=', $this->uid],
  54. ['password', '=', data_md5($this->params[ 'old_pass' ])]
  55. ];
  56. $res = $user_model->modifyAdminUserPassword($condition, $this->params[ 'new_pass' ]);
  57. return $this->response($res);
  58. }
  59. }