Register.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 Register extends BaseApi
  14. {
  15. /**
  16. * 用户名密码注册
  17. */
  18. public function register()
  19. {
  20. $config_model = new ConfigModel();
  21. $config_info = $config_model->getCaptchaConfig();
  22. $config = $config_info[ 'data' ][ 'value' ];
  23. $register = new UserModel();
  24. if (empty($this->params[ "username" ])) return $this->response($this->error([], "用户名不可为空!"));
  25. if (empty($this->params[ "password" ])) return $this->response($this->error([], "密码不可为空!"));
  26. // 校验验证码
  27. if ($config[ "shop_login" ] == 1) {
  28. $captcha = new Captcha();
  29. $check_res = $captcha->checkCaptcha();
  30. if ($check_res[ 'code' ] < 0) return $this->response($check_res);
  31. }
  32. $data[ 'username' ] = $this->params[ 'username' ];
  33. $data[ 'password' ] = $this->params[ 'password' ];
  34. $data[ 'app_module' ] = $this->app_module;
  35. $data[ 'site_id' ] = 0;
  36. $res = $register->addUser($data);
  37. //生成access_token
  38. if ($res[ 'code' ] >= 0) {
  39. $token = $this->createToken($res[ 'data' ]);
  40. return $this->response($this->success([ 'token' => $token, 'site_id' => $res[ 'data' ][ 'site_id' ] ]));
  41. }
  42. return $this->response($res);
  43. }
  44. }