Browse Source

用户相关接口

lizhen_gitee 6 months ago
parent
commit
c1e07586de
3 changed files with 26 additions and 22 deletions
  1. 6 10
      application/api/controller/User.php
  2. 19 12
      application/common/library/Auth.php
  3. 1 0
      application/extra/site.php

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

@@ -102,25 +102,21 @@ class User extends Api
      */
     public function register()
     {
-        $username = $this->request->post('username');
-        $password = $this->request->post('password');
-        $email = $this->request->post('email');
         $mobile = $this->request->post('mobile');
-        $code = $this->request->post('code');
-        if (!$username || !$password) {
+        $captcha = $this->request->post('captcha');
+        $password = $this->request->post('password');
+
+        if (!$mobile || !$captcha || !$password) {
             $this->error(__('Invalid parameters'));
         }
-        if ($email && !Validate::is($email, "email")) {
-            $this->error(__('Email is incorrect'));
-        }
         if ($mobile && !Validate::regex($mobile, "^1\d{10}$")) {
             $this->error(__('Mobile is incorrect'));
         }
-        $ret = Sms::check($mobile, $code, 'register');
+        $ret = Sms::check($mobile, $captcha, 'register');
         if (!$ret) {
             $this->error(__('Captcha is incorrect'));
         }
-        $ret = $this->auth->register($username, $password, $email, $mobile, []);
+        $ret = $this->auth->register('', $password, '', $mobile, []);
         if ($ret) {
             $data = $this->auth->getUserinfo_smiple();
             $this->success(__('Sign up successful'), $data);

+ 19 - 12
application/common/library/Auth.php

@@ -134,7 +134,7 @@ class Auth
     public function register($username, $password, $email = '', $mobile = '', $extend = [])
     {
         // 检测用户名、昵称、邮箱、手机号是否存在
-        if (User::getByUsername($username)) {
+        /*if (User::getByUsername($username)) {
             $this->setError('Username already exist');
             return false;
         }
@@ -142,10 +142,7 @@ class Auth
             $this->setError('Nickname already exist');
             return false;
         }
-        if ($email && User::getByEmail($email)) {
-            $this->setError('Email already exist');
-            return false;
-        }
+       */
         if ($mobile && User::getByMobile($mobile)) {
             $this->setError('Mobile already exist');
             return false;
@@ -155,17 +152,14 @@ class Auth
         $time = time();
 
         $data = [
-            'username' => $username,
+//            'username' => $username,
+            'nickname'  => get_rand_nick_name(),
             'password' => $password,
-            'email'    => $email,
+            'salt'      => Random::alnum(),
             'mobile'   => $mobile,
-            'level'    => 1,
-            'score'    => 0,
-            'avatar'   => '',
+            'avatar'   => config('site.user_default_avatar'),
         ];
         $params = array_merge($data, [
-            'nickname'  => preg_match("/^1[3-9]{1}\d{9}$/", $username) ? substr_replace($username, '****', 3, 4) : $username,
-            'salt'      => Random::alnum(),
             'jointime'  => $time,
             'joinip'    => $ip,
             'logintime' => $time,
@@ -182,6 +176,8 @@ class Auth
             $user = User::create($params, true);
 
             $this->_user = User::get($user->id);
+            $this->_user->username = 100000 + $user->id;
+            $this->_user->save();
 
             //设置Token
             $this->_token = Random::uuid();
@@ -190,6 +186,11 @@ class Auth
             //设置登录状态
             $this->_logined = true;
 
+            //注册钱包
+            Db::name('user_wallet')->insertGetId(['user_id'=>$user->id]);
+            //注册用户活跃
+            Db::name('user_active')->insertGetId(['user_id'=>$user->id]);
+
             //注册成功的事件
             Hook::listen("user_register_successed", $this->_user, $data);
             Db::commit();
@@ -389,6 +390,9 @@ class Auth
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
         $userinfo = array_merge($userinfo, Token::get($this->_token));
+
+        $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
+
         return $userinfo;
     }
     public function getUserinfo()
@@ -397,6 +401,9 @@ class Auth
         $allowFields = $this->getAllowFields();
         $userinfo = array_intersect_key($data, array_flip($allowFields));
         $userinfo = array_merge($userinfo, Token::get($this->_token));
+        
+        $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
+
         return $userinfo;
     }
 

+ 1 - 0
application/extra/site.php

@@ -59,4 +59,5 @@ return array (
   'user_ios_update_title' => '新的版本',
   'user_ios_update_info' => '界是你没有挽过的船新版本',
   'user_ios_pay_sandbox' => '0',
+  'user_default_avatar' => '/uploads/20241019/244017dc8c5a698037da7bab78da2d34.png',
 );