소스 검색

用户修改调整

zhangxiaobin 1 년 전
부모
커밋
54db3cecaf
2개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      application/api/controller/User.php
  2. 14 0
      application/common.php

+ 10 - 0
application/api/controller/User.php

@@ -200,6 +200,11 @@ class User extends Api
             $user->username = $username;
         }
         if ($nickname) {
+            //限制长度
+            $nicknameLen = mb_strlen($nickname);
+            if ($nicknameLen > 12) {
+                $this->error('昵称不能超过12个字');
+            }
             $exists = \app\common\model\User::where('nickname', $nickname)->where('id', '<>', $this->auth->id)->find();
             if ($exists) {
                 $this->error(__('Nickname already exist'));
@@ -207,6 +212,11 @@ class User extends Api
             $user->nickname = $nickname;
         }
         if ($mobile) {
+            //验证手机号
+            $isMobile = is_mobile($mobile);
+            if (!$isMobile) {
+                $this->error('手机号格式错误');
+            }
             $exists = \app\common\model\User::where('mobile', $mobile)->where('id', '<>', $this->auth->id)->find();
             if ($exists) {
                 $this->error(__('Mobile already exist'));

+ 14 - 0
application/common.php

@@ -1112,4 +1112,18 @@ if(!function_exists('httpRequest')) {
         return $response;
         //return array($http_code, $response,$requestinfo);
     }
+}
+if(!function_exists('is_mobile')) {
+    /**
+     * 手机格式验证
+     * @param string $mobile 验证的手机号码
+     * @return boolean
+     */
+    function is_mobile($mobile)
+    {
+        if (!empty($mobile)) {
+            return preg_match('/^1[3|4|5|6|7|8|9][0-9]\d{8}$/', $mobile);
+        }
+        return false;
+    }
 }