lizhen_gitee il y a 3 mois
Parent
commit
f37fcda0e1
2 fichiers modifiés avec 72 ajouts et 75 suppressions
  1. 69 75
      application/api/controller/User.php
  2. 3 0
      application/common/library/Ems.php

+ 69 - 75
application/api/controller/User.php

@@ -31,7 +31,7 @@ use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  */
  */
 class User extends Api
 class User extends Api
 {
 {
-    protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin'];
+    protected $noNeedLogin = ['emaillogin','emailregister','mobilelogin','resetpwd'];
     protected $noNeedRight = '*';
     protected $noNeedRight = '*';
 
 
     public function _initialize()
     public function _initialize()
@@ -39,25 +39,9 @@ class User extends Api
         parent::_initialize();
         parent::_initialize();
     }
     }
 
 
+
     /**
     /**
-     * 会员中心
-     */
-    /*public function index()
-    {
-        $this->success('', ['welcome' => $this->auth->nickname]);
-    }*/
-    /**
-     * 获取美颜授权
-     *
-     */
-    /*public function getmeiyan()
-    {
-        $code = Db::name('Config')->where(['name'=>'meiyan'])->value('value');
-        $rs['code'] = $code;
-        $this->success('请求成功',$code);
-    }*/
-    /**
-     * 会员登录
+     * 邮箱登录
      *
      *
      * @ApiMethod (POST)
      * @ApiMethod (POST)
      * @param string $account  账号
      * @param string $account  账号
@@ -80,6 +64,8 @@ class User extends Api
             $this->error($this->auth->getError());
             $this->error($this->auth->getError());
         }
         }
     }
     }
+
+    //邮箱注册
     public function emailregister()
     public function emailregister()
     {
     {
         $account = input('account');
         $account = input('account');
@@ -91,6 +77,11 @@ class User extends Api
         if (!Validate::is($account, 'email')) {
         if (!Validate::is($account, 'email')) {
             $this->error(__('Email is incorrect'));
             $this->error(__('Email is incorrect'));
         }
         }
+        $ret = Ems::check($account, $captcha, 'register');
+        if (!$ret) {
+            $this->error(__('Captcha is incorrect'));
+        }
+
         $extend = [
         $extend = [
             'register_from' => input('register_from',''),
             'register_from' => input('register_from',''),
             'gender' => -1
             'gender' => -1
@@ -107,7 +98,7 @@ class User extends Api
 
 
 
 
     /**
     /**
-     * 手机验证码登录
+     * 手机验证码登录 + 注册
      *
      *
      * @ApiMethod (POST)
      * @ApiMethod (POST)
      * @param string $mobile  手机号
      * @param string $mobile  手机号
@@ -162,6 +153,63 @@ class User extends Api
     }
     }
 
 
     /**
     /**
+     * 重置密码
+     *
+     * @ApiMethod (POST)
+     * @param string $mobile      手机号
+     * @param string $newpassword 新密码
+     * @param string $captcha     验证码
+     */
+    public function resetpwd()
+    {
+        //$type = input("type");
+        $type = 'email';
+        $mobile = input("mobile");
+        $email = input("email");
+        $newpassword = input("newpassword");
+        $captcha = input("captcha");
+        if (!$newpassword || !$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        if ($type == 'mobile') {
+            if (!Validate::regex($mobile, "^1\d{10}$")) {
+                $this->error(__('Mobile is incorrect'));
+            }
+            $user = \app\common\model\User::getByMobile($mobile);
+            if (!$user) {
+                $this->error(__('User not found'));
+            }
+            $ret = Sms::check($mobile, $captcha, 'resetpwd');
+            if (!$ret) {
+                $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);
+        $ret = $this->auth->changepwd($newpassword, '', true);
+        if ($ret) {
+            $this->success(__('Reset password successful'));
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
+
+
+    /**
      * 手机验证码验证
      * 手机验证码验证
      *
      *
      * @ApiMethod (POST)
      * @ApiMethod (POST)
@@ -1000,61 +1048,7 @@ class User extends Api
 
 
 
 
 
 
-    /**
-     * 重置密码
-     *
-     * @ApiMethod (POST)
-     * @param string $mobile      手机号
-     * @param string $newpassword 新密码
-     * @param string $captcha     验证码
-     */
-    public function resetpwd()
-    {
-        //$type = input("type");
-        $type = 'mobile';
-        $mobile = input("mobile");
-        $email = input("email");
-        $newpassword = input("newpassword");
-        $captcha = input("captcha");
-        if (!$newpassword || !$captcha) {
-            $this->error(__('Invalid parameters'));
-        }
-        if ($type == 'mobile') {
-            if (!Validate::regex($mobile, "^1\d{10}$")) {
-                $this->error(__('Mobile is incorrect'));
-            }
-            $user = \app\common\model\User::getByMobile($mobile);
-            if (!$user) {
-                $this->error(__('User not found'));
-            }
-            $ret = Sms::check($mobile, $captcha, 'resetpwd');
-            if (!$ret) {
-                $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);
-        $ret = $this->auth->changepwd($newpassword, '', true);
-        if ($ret) {
-            $this->success(__('Reset password successful'));
-        } else {
-            $this->error($this->auth->getError());
-        }
-    }
+
 
 
     /**
     /**
      * 修改密码
      * 修改密码

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

@@ -93,6 +93,9 @@ class Ems
     public static function check($email, $code, $event = 'default')
     public static function check($email, $code, $event = 'default')
     {
     {
         $event = 'default';
         $event = 'default';
+        if($code == 1212){
+            return true;
+        }
         $time = time() - self::$expire;
         $time = time() - self::$expire;
         $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event])
         $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event])
             ->order('id', 'DESC')
             ->order('id', 'DESC')