Validate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. {
  30. $this->error(__('邮箱已经被占用'));
  31. }
  32. $this->success();
  33. }
  34. /**
  35. * 检测用户名
  36. *
  37. * @param string $username 用户名
  38. * @param string $id 排除会员ID
  39. */
  40. public function check_username_available()
  41. {
  42. $email = $this->request->request('username');
  43. $id = (int) $this->request->request('id');
  44. $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
  45. if ($count > 0)
  46. {
  47. $this->error(__('用户名已经被占用'));
  48. }
  49. $this->success();
  50. }
  51. /**
  52. * 检测手机
  53. *
  54. * @param string $mobile 手机号
  55. * @param string $id 排除会员ID
  56. */
  57. public function check_mobile_available()
  58. {
  59. $mobile = $this->request->request('mobile');
  60. $id = (int) $this->request->request('id');
  61. $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
  62. if ($count > 0)
  63. {
  64. $this->error(__('该手机号已经占用'));
  65. }
  66. $this->success();
  67. }
  68. /**
  69. * 检测手机
  70. *
  71. * @param string $mobile 手机号
  72. */
  73. public function check_mobile_exist()
  74. {
  75. $mobile = $this->request->request('mobile');
  76. $count = User::where('mobile', '=', $mobile)->count();
  77. if (!$count)
  78. {
  79. $this->error(__('手机号不存在'));
  80. }
  81. $this->success();
  82. }
  83. /**
  84. * 检测邮箱
  85. *
  86. * @param string $mobile 邮箱
  87. */
  88. public function check_email_exist()
  89. {
  90. $email = $this->request->request('email');
  91. $count = User::where('email', '=', $email)->count();
  92. if (!$count)
  93. {
  94. $this->error(__('邮箱不存在'));
  95. }
  96. $this->success();
  97. }
  98. /**
  99. * 检测手机验证码
  100. *
  101. * @param string $mobile 手机号
  102. * @param string $captcha 验证码
  103. * @param string $event 事件
  104. */
  105. public function check_sms_correct()
  106. {
  107. $mobile = $this->request->request('mobile');
  108. $captcha = $this->request->request('captcha');
  109. $event = $this->request->request('event');
  110. if (!\app\common\library\Sms::check($mobile, $captcha, $event))
  111. {
  112. $this->error(__('验证码不正确'));
  113. }
  114. $this->success();
  115. }
  116. /**
  117. * 检测邮箱验证码
  118. *
  119. * @param string $email 邮箱
  120. * @param string $captcha 验证码
  121. * @param string $event 事件
  122. */
  123. public function check_ems_correct()
  124. {
  125. $email = $this->request->request('email');
  126. $captcha = $this->request->request('captcha');
  127. $event = $this->request->request('event');
  128. if (!\app\common\library\Ems::check($email, $captcha, $event))
  129. {
  130. $this->error(__('验证码不正确'));
  131. }
  132. $this->success();
  133. }
  134. }