Validate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 __construct(){
  14. $this->error('投票活动结束了');
  15. }
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. /**
  21. * 检测邮箱
  22. *
  23. * @ApiMethod (POST)
  24. * @param string $email 邮箱
  25. * @param string $id 排除会员ID
  26. */
  27. public function check_email_available()
  28. {
  29. $email = $this->request->post('email');
  30. $id = (int)$this->request->post('id');
  31. $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
  32. if ($count > 0) {
  33. $this->error(__('邮箱已经被占用'));
  34. }
  35. $this->success();
  36. }
  37. /**
  38. * 检测用户名
  39. *
  40. * @ApiMethod (POST)
  41. * @param string $username 用户名
  42. * @param string $id 排除会员ID
  43. */
  44. public function check_username_available()
  45. {
  46. $username = $this->request->post('username');
  47. $id = (int)$this->request->post('id');
  48. $count = User::where('username', '=', $username)->where('id', '<>', $id)->count();
  49. if ($count > 0) {
  50. $this->error(__('用户名已经被占用'));
  51. }
  52. $this->success();
  53. }
  54. /**
  55. * 检测昵称
  56. *
  57. * @ApiMethod (POST)
  58. * @param string $nickname 昵称
  59. * @param string $id 排除会员ID
  60. */
  61. public function check_nickname_available()
  62. {
  63. $nickname = $this->request->post('nickname');
  64. $id = (int)$this->request->post('id');
  65. $count = User::where('nickname', '=', $nickname)->where('id', '<>', $id)->count();
  66. if ($count > 0) {
  67. $this->error(__('昵称已经被占用'));
  68. }
  69. $this->success();
  70. }
  71. /**
  72. * 检测手机
  73. *
  74. * @ApiMethod (POST)
  75. * @param string $mobile 手机号
  76. * @param string $id 排除会员ID
  77. */
  78. public function check_mobile_available()
  79. {
  80. $mobile = $this->request->post('mobile');
  81. $id = (int)$this->request->post('id');
  82. $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
  83. if ($count > 0) {
  84. $this->error(__('该手机号已经占用'));
  85. }
  86. $this->success();
  87. }
  88. /**
  89. * 检测手机
  90. *
  91. * @ApiMethod (POST)
  92. * @param string $mobile 手机号
  93. */
  94. public function check_mobile_exist()
  95. {
  96. $mobile = $this->request->post('mobile');
  97. $count = User::where('mobile', '=', $mobile)->count();
  98. if (!$count) {
  99. $this->error(__('手机号不存在'));
  100. }
  101. $this->success();
  102. }
  103. /**
  104. * 检测邮箱
  105. *
  106. * @ApiMethod (POST)
  107. * @param string $mobile 邮箱
  108. */
  109. public function check_email_exist()
  110. {
  111. $email = $this->request->post('email');
  112. $count = User::where('email', '=', $email)->count();
  113. if (!$count) {
  114. $this->error(__('邮箱不存在'));
  115. }
  116. $this->success();
  117. }
  118. /**
  119. * 检测手机验证码
  120. *
  121. * @ApiMethod (POST)
  122. * @param string $mobile 手机号
  123. * @param string $captcha 验证码
  124. * @param string $event 事件
  125. */
  126. public function check_sms_correct()
  127. {
  128. $mobile = $this->request->post('mobile');
  129. $captcha = $this->request->post('captcha');
  130. $event = $this->request->post('event');
  131. if (!\app\common\library\Sms::check($mobile, $captcha, $event)) {
  132. $this->error(__('验证码不正确'));
  133. }
  134. $this->success();
  135. }
  136. /**
  137. * 检测邮箱验证码
  138. *
  139. * @ApiMethod (POST)
  140. * @param string $email 邮箱
  141. * @param string $captcha 验证码
  142. * @param string $event 事件
  143. */
  144. public function check_ems_correct()
  145. {
  146. $email = $this->request->post('email');
  147. $captcha = $this->request->post('captcha');
  148. $event = $this->request->post('event');
  149. if (!\app\common\library\Ems::check($email, $captcha, $event)) {
  150. $this->error(__('验证码不正确'));
  151. }
  152. $this->success();
  153. }
  154. }