lizhen_gitee vor 3 Monaten
Ursprung
Commit
56b1eb450c

+ 5 - 7
application/api/controller/User.php

@@ -31,7 +31,7 @@ use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'mobilelogin','wechatlogin','wechatbindmobile', 'register', 'resetpwd', 'changeemail', 'changemobile', 'onlogin','getUserOpenid_gzh','jssdkBuildConfig', 'mobileregister', 'mobilecheck', 'wechatregiter', 'onregister', 'ioslogin', 'iosregiter'];
+    protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -75,8 +75,7 @@ class User extends Api
         }
         $ret = $this->auth->login($account, $password);
         if ($ret) {
-            $data = $this->userInfo('return');
-            $this->success(__('Logged in successful'), $data);
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
         } else {
             $this->error($this->auth->getError());
         }
@@ -98,8 +97,8 @@ class User extends Api
         ];
         $ret = $this->auth->register('',$password,$account,'', $extend);
         if ($ret) {
-            $data = $this->userInfo('return');
-            $this->success(__('Logged in successful'), $data);
+            Ems::flush($account);
+            $this->success('注册成功', $this->auth->getUserinfo_simple());
         } else {
             $this->error($this->auth->getError());
         }
@@ -156,8 +155,7 @@ class User extends Api
         }
         if ($ret) {
             Sms::flush($mobile, 'mobilelogin');
-            $data = $this->userInfo('return');
-            $this->success(__('Logged in successful'), $data);
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
         } else {
             $this->error($this->auth->getError());
         }

+ 28 - 8
application/common/library/Auth.php

@@ -216,11 +216,17 @@ class Auth
      * @param array  $extend   扩展参数
      * @return boolean
      */
-    public function register($username, $password, $email = '', $mobile = '', $extend = [])
+    public function register($username, $password = '', $email = '', $mobile = '', $extend = [])
     {
 
 
 
+        if ($email && User::getByEmail($email)) {
+            $this->setError('Email already exist');
+            return false;
+        }
+
+
         if ($mobile && User::getByMobile($mobile)) {
             $this->setError('Mobile already exist');
             return false;
@@ -232,14 +238,21 @@ class Auth
         $introcode = User::column("introcode");
 
         $data = [
+            'email'   => $email,
             'mobile'   => $mobile,
-            /*'level'    => 1,
-            'score'    => 0,*/
+
             'avatar' => $extend['gender'] == 1 ? config('avatar_boy') : config('avatar_girl'),
             'introcode' => $this->getUinqueNo(6, $introcode),
+            'nickname'  => $this->get_rand_nick_name(),
+
         ];
+
+        if($password){
+            $data['salt'] = Random::alnum();
+            $data['password'] = $this->getEncryptPassword($password, $data['salt']);
+        }
+
         $params = array_merge($data, [
-            'nickname'  => $this->get_rand_nick_name(),
             'jointime'  => $time,
             'joinip'    => $ip,
             'logintime' => $time,
@@ -500,7 +513,7 @@ class Auth
     public function login($account, $password)
     {
         //$field = Validate::is($account, 'email') ? 'email' : (Validate::regex($account, '/^1\d{10}$/') ? 'mobile' : 'username');
-        $field = 'mobile';
+        $field = 'email';
         $user = User::get([$field => $account]);
         if (!$user) {
             $this->setError('Account is incorrect');
@@ -521,9 +534,7 @@ class Auth
         }
 
         //直接登录会员
-        $this->direct($user->id);
-
-        return true;
+        return $this->direct($user->id);
     }
 
     /**
@@ -679,6 +690,15 @@ class Auth
     /**
      * 获取会员基本信息
      */
+    public function getUserinfo_simple(){
+        $user_info = Token::get($this->_token);
+        $user_info['id'] = $user_info['user_id'];
+        return $user_info;
+    }
+
+    /**
+     * 获取会员基本信息
+     */
     public function getUserinfo()
     {
         $data = $this->_user->toArray();

+ 4 - 0
application/common/library/Ems.php

@@ -31,6 +31,7 @@ class Ems
      */
     public static function get($email, $event = 'default')
     {
+        $event = 'default';
         $ems = \app\common\model\Ems::
         where(['email' => $email, 'event' => $event])
             ->order('id', 'DESC')
@@ -49,6 +50,7 @@ class Ems
      */
     public static function send($email, $code = null, $event = 'default')
     {
+        $event = 'default';
         $code = is_null($code) ? mt_rand(1000, 9999) : $code;
         $time = time();
         $ip = request()->ip();
@@ -90,6 +92,7 @@ class Ems
      */
     public static function check($email, $code, $event = 'default')
     {
+        $event = 'default';
         $time = time() - self::$expire;
         $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event])
             ->order('id', 'DESC')
@@ -124,6 +127,7 @@ class Ems
      */
     public static function flush($email, $event = 'default')
     {
+        $event = 'default';
         \app\common\model\Ems::
         where(['email' => $email, 'event' => $event])
             ->delete();