Browse Source

modify empty to isset

stanley-king 9 years ago
parent
commit
0139b7e2eb
5 changed files with 38 additions and 19 deletions
  1. 9 7
      debug_run.php
  2. 12 10
      mobile/control/login.php
  3. 2 0
      mobile/util/errcode.php
  4. 13 0
      research/function_test.php
  5. 2 2
      research_run.php

+ 9 - 7
debug_run.php

@@ -6,16 +6,18 @@ $reqs = array();
 //$reqs['index'] ='http://localhost:8080/mobile/index.php?act=index&op=index';
 //$reqs['login_register'] ='http://localhost:8080/mobile/index.php?act=login&op=register&username=stanley&password=55668899&password_confirm=55668899';
 
-$reqs['login_genanonymous'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&info=helloworld&type=1&client=android';
-//$reqs['login_genwx'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&type=2&openid=123456789000';
-
-//$reqs['login_anonymous_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=fc5e038d38a57032085441e7fe7010b0&type=1&client=android';
+//$reqs['login_genanonymous'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&info=helloworld&type=1&client=android';
+//$reqs['login_genwx'] ='http://localhost:8080/mobile/index.php?act=login&op=genuser&type=2&openid=123456789000&client=android';
 
+//$reqs['login_anonymous_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=561f708422817&type=1&client=android';
 //$reqs['login_wx_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&openid=123456789000&type=2&client=android';
-//$reqs['login_wx_getinfo'] ='http://localhost:8080/mobile/index.php?act=login&op=getinfo&token=4bb087069ba382e8c62cee3ce16ea8d6';
+//$reqs['login_mobile_login'] ='http://localhost:8080/mobile/index.php?act=login&op=login&mobile=18022196345&password=55668899&type=0&client=android';
+
+
+//$reqs['login_wx_getinfo'] ='http://localhost:8080/mobile/index.php?act=login&op=getinfo&token=08a6a71c051bc5be33f85141f3ca6b52';
 
-//$reqs['login_wx_getcode'] ='http://localhost:8080/mobile/index.php?act=login&op=getcode&token=4bb087069ba382e8c62cee3ce16ea8d6&mobile=13911129867';
-//$reqs['login_wx_getcode'] ='http://localhost:8080/mobile/index.php?act=login&op=checkcode&token=4bb087069ba382e8c62cee3ce16ea8d6&code=5591';
+//$reqs['login_wx_getcode'] ='http://localhost:8080/mobile/index.php?act=login&op=getcode&token=08a6a71c051bc5be33f85141f3ca6b52&mobile=13911129867';
+//$reqs['login_wx_checkcode'] ='http://localhost:8080/mobile/index.php?act=login&op=checkcode&token=08a6a71c051bc5be33f85141f3ca6b52&code=0369';
 
 
 

+ 12 - 10
mobile/control/login.php

@@ -27,18 +27,18 @@ class loginControl extends mobileHomeControl
             return joutput_error(errcode::ErrApptype);
         }
         
-        $type = trim($_POST['type']);    
-        if(empty($type) || !in_array($type, $this->client_login_type_array)) {
+        $type = trim($_POST['type']);   
+        if(!isset($type) || !in_array($type, $this->client_login_type_array)) {
             return joutput_error(errcode::ErrParamter,'type error.');
         }
 
         $validate = new Validate();
         
-        $openid = trim($_POST['openid']);
-        if($type == memberModel::mobile_login) {            
+        if($type == memberModel::mobile_login) {  
+            $openid = trim($_POST['mobile']);
             $password = trim($_POST['password']);
             $validate->setValidate(Validate::verify_mobile($openid));
-            $validate->setValidate(Validate::verify_password($password));          
+            $validate->setValidate(Validate::verify_password($password));     
         } else {
             $openid = trim($_POST['openid']);
             $validate->setValidate(Validate::verify_openid($openid));
@@ -80,7 +80,7 @@ class loginControl extends mobileHomeControl
         } 
 
         $type = $_POST['type'];   
-        if(empty($type) || !in_array($type, $this->client_login_type_array)) {
+        if(!isset($type) || !in_array($type, $this->client_login_type_array)) {
             return joutput_error(errcode::ErrParamter,'type error.');
         } 
         
@@ -139,7 +139,7 @@ class loginControl extends mobileHomeControl
         static $bind_types = array('mobile','wx');
 
         $type = trim($_POST['type']);
-        if(empty($type) || !in_array($type, $bind_types)) {
+        if(!isset($type) || !in_array($type, $bind_types)) {
             return joutput_error(errcode::ErrParamter,'Bind type error,only support mobile and wx.');
         } 
 
@@ -288,7 +288,7 @@ class loginControl extends mobileHomeControl
 
         $validator = new Validate();
 
-        $code = $trim($_POST['code']);        
+        $code = trim($_POST['code']);        
         $validator->setValidate(Validate::smscode($code));
         $err = $validator->validate();
         if($err != '') {
@@ -297,10 +297,12 @@ class loginControl extends mobileHomeControl
 
         $key = $this->gen_token_code($token);
         $ret = rcache($key,'member');
-        if(!empty($ret) && $ret['code'] == $code) {
+        if(empty($ret)) {
+            joutput_error(errcode::ErrSmscodeExpire);
+        } elseif ($ret['code'] == $code) {
             joutput_data(NULL);            
         } else {
-            joutput_error(errcode::ErrSmscodeExpire);            
+            joutput_error(errcode::ErrSmscode);                        
         }        
     }
     

+ 2 - 0
mobile/util/errcode.php

@@ -12,6 +12,7 @@ class errcode extends SplEnum
     const ErrUsertype = 10004;
     const ErrTokenExpire = 10005;
     const ErrSmscodeExpire = 10006;
+    const ErrSmscode = 10007;
 
     const ErrDB      = 11000;
 
@@ -29,6 +30,7 @@ class errcode extends SplEnum
             case errcode::ErrUsertype : return 'ErrUsertype';
             case errcode::ErrTokenExpire : return 'ErrTokenExpire';
             case errcode::ErrSmscodeExpire : return 'ErrSmscodeExpire';
+            case errcode::ErrSmscode: return 'ErrSmscode';
 
             case errcode::ErrDB : return 'ErrorDB';
 

+ 13 - 0
research/function_test.php

@@ -2,6 +2,19 @@
 
 require_once(BASE_CORE_PATH . '/framework/libraries/validate.php');
 
+
+$datas = array('type' => 0,'mobile' => '13911129867','str' => '');
+
+$var = $datas['str'];
+
+if(empty($var)) {
+    echo "$var";
+}
+
+if(isset($var)) {
+    echo "$var";
+}
+
 $a = new Validate();
 //$a->setValidate("344d",true,"","不可以为空");
 $a->setValidate(array('input'=>"haizi.king@gmial.com",'validator' => "Email", 'message' =>"请填写正确的EMAIL"));

+ 2 - 2
research_run.php

@@ -8,8 +8,8 @@
 Base::run_test();
 
 
-include BASE_ROOT_PATH . "/research/db.php";
-//include BASE_ROOT_PATH . "/research/function_test.php";
+//include BASE_ROOT_PATH . "/research/db.php";
+include BASE_ROOT_PATH . "/research/function_test.php";
 //include BASE_ROOT_PATH . "/research/sms_test.php";