You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 lines
3.5 KiB

  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\User;
  5. /**
  6. * 验证接口
  7. */
  8. class Validate extends Api
  9. {
  10. protected $noNeedLogin = '*';
  11. protected $layout = '';
  12. protected $error = null;
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. /**
  18. * 检测邮箱
  19. *
  20. * @param string $email 邮箱
  21. * @param string $id 排除会员ID
  22. */
  23. public function check_email_available()
  24. {
  25. $email = $this->request->request('email');
  26. $id = (int)$this->request->request('id');
  27. $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
  28. if ($count > 0) {
  29. $this->error(__('邮箱已经被占用'));
  30. }
  31. $this->success();
  32. }
  33. /**
  34. * 检测用户名
  35. *
  36. * @param string $username 用户名
  37. * @param string $id 排除会员ID
  38. */
  39. public function check_username_available()
  40. {
  41. $email = $this->request->request('username');
  42. $id = (int)$this->request->request('id');
  43. $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
  44. if ($count > 0) {
  45. $this->error(__('用户名已经被占用'));
  46. }
  47. $this->success();
  48. }
  49. /**
  50. * 检测手机
  51. *
  52. * @param string $mobile 手机号
  53. * @param string $id 排除会员ID
  54. */
  55. public function check_mobile_available()
  56. {
  57. $mobile = $this->request->request('mobile');
  58. $id = (int)$this->request->request('id');
  59. $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
  60. if ($count > 0) {
  61. $this->error(__('该手机号已经占用'));
  62. }
  63. $this->success();
  64. }
  65. /**
  66. * 检测手机
  67. *
  68. * @param string $mobile 手机号
  69. */
  70. public function check_mobile_exist()
  71. {
  72. $mobile = $this->request->request('mobile');
  73. $count = User::where('mobile', '=', $mobile)->count();
  74. if (!$count) {
  75. $this->error(__('手机号不存在'));
  76. }
  77. $this->success();
  78. }
  79. /**
  80. * 检测邮箱
  81. *
  82. * @param string $mobile 邮箱
  83. */
  84. public function check_email_exist()
  85. {
  86. $email = $this->request->request('email');
  87. $count = User::where('email', '=', $email)->count();
  88. if (!$count) {
  89. $this->error(__('邮箱不存在'));
  90. }
  91. $this->success();
  92. }
  93. /**
  94. * 检测手机验证码
  95. *
  96. * @param string $mobile 手机号
  97. * @param string $captcha 验证码
  98. * @param string $event 事件
  99. */
  100. public function check_sms_correct()
  101. {
  102. $mobile = $this->request->request('mobile');
  103. $captcha = $this->request->request('captcha');
  104. $event = $this->request->request('event');
  105. if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
  106. $this->error(__('验证码不正确'));
  107. }
  108. $this->success();
  109. }
  110. /**
  111. * 检测邮箱验证码
  112. *
  113. * @param string $email 邮箱
  114. * @param string $captcha 验证码
  115. * @param string $event 事件
  116. */
  117. public function check_ems_correct()
  118. {
  119. $email = $this->request->request('email');
  120. $captcha = $this->request->request('captcha');
  121. $event = $this->request->request('event');
  122. if (!\app\common\library\Ems::check($email, $captcha, $event)) {
  123. $this->error(__('验证码不正确'));
  124. }
  125. $this->success();
  126. }
  127. }