Browse Source

手机号+区号防重复

lizhen_gitee 1 năm trước cách đây
mục cha
commit
86946f530a

+ 5 - 4
application/api/controller/Sms.php

@@ -41,10 +41,11 @@ class Sms extends Api
         $event = input("event",'default');
         $event = $event ? $event : 'register';
 
+        $fullmobile = $countrycode.$mobile;
         if (!$mobile) {
             $this->error(__('手机号不正确'));
         }
-        $last = Smslib::get($mobile, $event);
+        $last = Smslib::get($fullmobile, $event);
         if ($last && time() - $last['createtime'] < 60) {
             $this->error(__('发送频繁'));
         }
@@ -53,7 +54,7 @@ class Sms extends Api
             $this->error(__('发送频繁'));
         }
         if ($event) {
-            $userinfo = User::getByMobile($mobile);
+            $userinfo = User::getByMobile($fullmobile);
             if ($event == 'register' && $userinfo) {
                 //已被注册
                 $this->error(__('已被注册'));
@@ -84,7 +85,7 @@ class Sms extends Api
      * @param string $event 事件名称
      * @param string $captcha 验证码
      */
-    public function check()
+    /*public function check()
     {
         $mobile = $this->request->post("mobile");
         $event = $this->request->post("event",'default');
@@ -113,5 +114,5 @@ class Sms extends Api
         } else {
             $this->error(__('验证码不正确'));
         }
-    }
+    }*/
 }

+ 24 - 22
application/api/controller/User.php

@@ -49,11 +49,15 @@ class User extends Api
      */
     public function login()
     {
+        $countrycode = input('countrycode');
         $account = input('account');
         $password = input('password');
-        if (!$account || !$password) {
+
+        if (!$countrycode || !$account || !$password) {
             $this->error(__('Invalid parameters'));
         }
+
+        $account = $countrycode.$account;
         $ret = $this->auth->login($account, $password);
         if ($ret) {
             $data = $this->userInfo('return');
@@ -73,16 +77,17 @@ class User extends Api
      */
     public function mobilelogin()
     {
-
+        $countrycode = input('countrycode');
         $mobile = input('mobile');
         $captcha = input('captcha');
 
-        if (!$mobile || !$captcha) {
+        if (!$countrycode || !$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
         /*if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }*/
+        $mobile = $countrycode.$mobile;
         if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
             $this->error(__('Captcha is incorrect'));
         }
@@ -257,7 +262,8 @@ class User extends Api
             } else {
                 // 取号成功, 执行登录等流程
                 // 用户登录逻辑 === 开始
-
+                $countrycode = 86;
+                $mobile = $countrycode.$mobile;
                 $user = \app\common\model\User::getByMobile($mobile);
                 if ($user) {
                     if ($user->status == -1) {
@@ -548,14 +554,16 @@ class User extends Api
     {
         $user = $this->auth->getUser();
         $oldcaptcha = $this->request->request('oldcaptcha');
+        $countrycode = $this->request->request('countrycode');
         $mobile = $this->request->request('mobile');
         $captcha = $this->request->request('captcha');
-        if (!$oldcaptcha || !$mobile || !$captcha) {
+        if (!$oldcaptcha || !$countrycode || !$mobile || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
         /*if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }*/
+        $mobile = $countrycode.$mobile;
         if($user->mobile == $mobile){
             $this->error('新手机号不能与旧手机号相同');
         }
@@ -590,16 +598,18 @@ class User extends Api
      */
     public function applebindmobile()
     {
+        $countrycode = $this->request->request('countrycode');
         $mobile    = $this->request->param('mobile');
         $captcha   = $this->request->param('captcha');
         $iosUserId = $this->request->param('ios_user_id','');
 
-        if (!$mobile || !$captcha || !$iosUserId) {
+        if (!$countrycode || !$mobile || !$captcha || !$iosUserId) {
             $this->error(__('Invalid parameters'));
         }
         /*if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }*/
+        $mobile = $countrycode.$mobile;
         $result = Sms::check($mobile, $captcha, 'changemobile');
         if (!$result) {
             $this->error(__('Captcha is incorrect'));
@@ -656,16 +666,18 @@ class User extends Api
      */
     public function bindmobile()
     {
+        $countrycode = $this->request->param('countrycode');
         $mobile = $this->request->param('mobile');
         $captcha = $this->request->param('captcha');
         $code = $this->request->param('code');
 
-        if (!$mobile || !$captcha || !$code) {
+        if (!$countrycode || !$mobile || !$captcha || !$code) {
             $this->error(__('Invalid parameters'));
         }
         /*if (!Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }*/
+        $mobile = $countrycode.$mobile;
         $result = Sms::check($mobile, $captcha, 'changemobile');
         if (!$result) {
             $this->error(__('Captcha is incorrect'));
@@ -760,13 +772,16 @@ class User extends Api
     {
         //$type = input("type");
         $type = 'mobile';
+        $countrycode = input("countrycode");
         $mobile = input("mobile");
-        $email = input("email");
+//        $email = input("email");
         $newpassword = input("newpassword");
         $captcha = input("captcha");
-        if (!$newpassword || !$captcha) {
+        if (!$countrycode || !$mobile || !$newpassword || !$captcha) {
             $this->error(__('Invalid parameters'));
         }
+
+        $mobile = $countrycode.$mobile;
         if ($type == 'mobile') {
             /*if (!Validate::regex($mobile, "^1\d{10}$")) {
                 $this->error(__('Mobile is incorrect'));
@@ -780,19 +795,6 @@ class User extends Api
                 $this->error(__('Captcha is incorrect'));
             }
             Sms::flush($mobile, 'resetpwd');
-        } else {
-            if (!Validate::is($email, "email")) {
-                $this->error(__('Email is incorrect'));
-            }
-            $user = \app\common\model\User::getByEmail($email);
-            if (!$user) {
-                $this->error(__('User not found'));
-            }
-            $ret = Ems::check($email, $captcha, 'resetpwd');
-            if (!$ret) {
-                $this->error(__('Captcha is incorrect'));
-            }
-            Ems::flush($email, 'resetpwd');
         }
         //模拟一次登录
         $this->auth->direct($user->id);

+ 2 - 2
application/api/controller/Validate.php

@@ -131,7 +131,7 @@ class Validate extends Api
      * @param string $captcha 验证码
      * @param string $event   事件
      */
-    public function check_sms_correct()
+    /*public function check_sms_correct()
     {
         $mobile = $this->request->post('mobile');
         $captcha = $this->request->post('captcha');
@@ -140,7 +140,7 @@ class Validate extends Api
             $this->error(__('验证码不正确'));
         }
         $this->success();
-    }
+    }*/
 
     /**
      * 检测邮箱验证码

+ 1 - 1
application/common/library/Sms.php

@@ -54,7 +54,7 @@ class Sms
         $code = is_null($code) ? mt_rand(1000, 9999) : $code;
         $time = time();
         $ip = request()->ip();
-        $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time, 'countrycode' => $countrycode]);
+        $sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $countrycode.$mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time, 'countrycode' => $countrycode]);
 //        $result = Hook::listen('sms_send', $sms, null, true);
 
         //阿里短信