Validate.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. $email = $this->request->request('mobile');
  60. $id = (int) $this->request->request('id');
  61. $count = User::where('mobile', '=', $email)->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. $email = $this->request->request('mobile');
  76. $count = User::where('mobile', '=', $email)->count();
  77. if (!$count)
  78. {
  79. $this->error(__('手机号不存在'));
  80. }
  81. $this->success();
  82. }
  83. /**
  84. * 检测验证码
  85. *
  86. * @param string $mobile 手机号
  87. * @param string $captcha 验证码
  88. * @param string $event 事件
  89. */
  90. public function check_sms_correct()
  91. {
  92. $mobile = $this->request->request('mobile');
  93. $captcha = $this->request->request('captcha');
  94. $event = $this->request->request('event');
  95. if (!\app\common\library\Sms::check($mobile, $captcha, $event))
  96. {
  97. $this->error(__('验证码不正确'));
  98. }
  99. $this->success();
  100. }
  101. }