Jelajahi Sumber

小程序登å½注册

wugg 1 tahun lalu
induk
melakukan
8bc49da08b
3 mengubah file dengan 10 tambahan dan 14 penghapusan
  1. 3 4
      app/api/controller/Wechat.php
  2. 3 3
      app/api/validate/User.php
  3. 4 7
      app/common/library/Auth.php

+ 3 - 4
app/api/controller/Wechat.php

@@ -38,17 +38,16 @@ class Wechat extends Frontend
             ], 302);
         }
          if ($this->request->isPost()) {
-            $params = $this->request->post([ 'mobile', 'nickname', 'avatar','openid','unionid', "keep",
-            'registerType'=>"wx"]);
+            $params = $this->request->post(['openid','unionid', "keep", 'registerType'=>"wx"]);
             $validate = new UserValidate();
             try {
                 $validate->scene("wechat")->check($params);
-            } catch (ValidateException $e) {
+            } catch (ValidateException $e){
                 $this->error($e->getMessage());
             }
 		    $res = $this->auth->isWxUser($params['openid'], $params['unionid'], (bool)$params['keep']);
             if (!$res) {
-                $res = $this->auth->WxRegister($params['nickname'], $params['mobile'], $params['openid'], $params['openid'],$params['avatar']);
+                $res = $this->auth->WxRegister( $params['openid'], $params['unionid']);
             }
 
             if (isset($res) && $res === true) {

+ 3 - 3
app/api/validate/User.php

@@ -16,8 +16,8 @@ class User extends Validate
         'captcha'     => 'require',
         'captchaId'   => 'require',
         'captchaInfo' => 'require',
-        "openid"=>"require",
-        "nickname"=>"require"
+        "openid"=>"require|unique:user,openid&unionid",
+
     ];
 
     /**
@@ -26,7 +26,7 @@ class User extends Validate
     protected $scene = [
         'login'    => ['password', 'captchaId', 'captchaInfo'],
         'register' => ['email', 'username', 'password', 'mobile', 'captcha'],
-        'wechat' => [ 'mobile', 'nickname',"openid","unionid"],
+        'wechat' => ["openid","unionid"],
     ];
 
     public function __construct()

+ 4 - 7
app/common/library/Auth.php

@@ -290,13 +290,11 @@ class Auth extends \ba\Auth
         return true;
     }
 
-    public function WxRegister(string $nickname, string $mobile, string $openid, string $unionid,string $avatar,$group=1,array $extend=[]){
+    public function WxRegister(string $openid, string $unionid,string $nickname='', string $mobile='',string $avatar='',
+    $group=1,array $extend=[]){
     	$validate = Validate::rule([
-            'mobile'   => 'mobile|unique:user',
-            'openid'    => 'require|unique:user',
+            'openid'    => 'require|unique:user,openid^unionid',
             'unionid' => 'max:255',
-            'nickname' => 'max:255',
-            'avatar' => 'url',
         ]);
         $params   = [
             'nickname' => $nickname,
@@ -314,9 +312,8 @@ class Auth extends \ba\Auth
         $time = time();
         $salt = Random::build('alnum', 16);
         $data = [
-            'password'      => encrypt_password(substr($mobile,3,6), $salt),
+            'password'      => '',
             'group_id'      => $group,
-            'nickname'      => $nickname=='' ? substr_replace($mobile, '****', 3, 4) : $nickname,
             'joinip'        => $ip,
             'jointime'      => $time,
             'lastloginip'   => $ip,