Validate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 $nickname 昵称
  53. * @param string $id 排除会员ID
  54. */
  55. public function check_nickname_available()
  56. {
  57. $email = $this->request->request('nickname');
  58. $id = (int)$this->request->request('id');
  59. $count = User::where('nickname', '=', $email)->where('id', '<>', $id)->count();
  60. if ($count > 0) {
  61. $this->error(__('昵称已经被占用'));
  62. }
  63. $this->success();
  64. }
  65. /**
  66. * 检测手机
  67. *
  68. * @param string $mobile 手机号
  69. * @param string $id 排除会员ID
  70. */
  71. public function check_mobile_available()
  72. {
  73. $mobile = $this->request->request('mobile');
  74. $id = (int)$this->request->request('id');
  75. $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
  76. if ($count > 0) {
  77. $this->error(__('该手机号已经占用'));
  78. }
  79. $this->success();
  80. }
  81. /**
  82. * 检测手机
  83. *
  84. * @param string $mobile 手机号
  85. */
  86. public function check_mobile_exist()
  87. {
  88. $mobile = $this->request->request('mobile');
  89. $count = User::where('mobile', '=', $mobile)->count();
  90. if (!$count) {
  91. $this->error(__('手机号不存在'));
  92. }
  93. $this->success();
  94. }
  95. /**
  96. * 检测邮箱
  97. *
  98. * @param string $mobile 邮箱
  99. */
  100. public function check_email_exist()
  101. {
  102. $email = $this->request->request('email');
  103. $count = User::where('email', '=', $email)->count();
  104. if (!$count) {
  105. $this->error(__('邮箱不存在'));
  106. }
  107. $this->success();
  108. }
  109. /**
  110. * 检测手机验证码
  111. *
  112. * @param string $mobile 手机号
  113. * @param string $captcha 验证码
  114. * @param string $event 事件
  115. */
  116. public function check_sms_correct()
  117. {
  118. $mobile = $this->request->request('mobile');
  119. $captcha = $this->request->request('captcha');
  120. $event = $this->request->request('event');
  121. if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
  122. $this->error(__('验证码不正确'));
  123. }
  124. $this->success();
  125. }
  126. /**
  127. * 检测邮箱验证码
  128. *
  129. * @param string $email 邮箱
  130. * @param string $captcha 验证码
  131. * @param string $event 事件
  132. */
  133. public function check_ems_correct()
  134. {
  135. $email = $this->request->request('email');
  136. $captcha = $this->request->request('captcha');
  137. $event = $this->request->request('event');
  138. if (!\app\common\library\Ems::check($email, $captcha, $event)) {
  139. $this->error(__('验证码不正确'));
  140. }
  141. $this->success();
  142. }
  143. }