fuyu 6 年之前
父节点
当前提交
46ba97b910
共有 1 个文件被更改,包括 39 次插入7 次删除
  1. 39 7
      application/inter/controller/Login.php

+ 39 - 7
application/inter/controller/Login.php

@@ -104,6 +104,7 @@ class Login extends Controller
                 Cache::set('sendcode_'.$phone,$code,600);
                 Cache::set('sendcode_handle_id'.$handle_id, $phone, 600);
                 $info = send_message::sendSms2UpDate($phone,$code);
+                log::record("login() set code => {handle_id: $handle_id \t code: $code \t phone: $phone \t}");
                 return json_encode(['status'=>'ok','code'=>'0000','need_code'=> true, 'phone' => $phone, 'handle_id' => $handle_id]);
             }
 
@@ -137,14 +138,28 @@ class Login extends Controller
     {
         try{
             $param = $_REQUEST['param'];
+
+            // 获取 handle_id
+            if(isset($param['handle_id']) || empty($param['handle_id'])) {
+                return json_encode(['status'=>'fail','code'=>'2001','msg'=>'系统错误 not find handle id']);
+            }
             $handle_id = $param['handle_id'];
+
+            // 获取 phone
+            if(!Cache::has('sendcode_handle_id'.$handle_id)) {
+                return json_encode(['status'=>'fail','code'=>'2002','msg'=>'操作过时,请重新登录']);
+            }
+
+            // 发送验证码并记录
             $phone = Cache::get('sendcode_handle_id'.$handle_id);
-            $code = rand('1000','9999');
             Cache::rm('sendcode_handle_id'.$handle_id);
+
+            $code = rand('1000','9999');
             $info = send_message::sendSms2UpDate($phone,$code);
             $handle_id = $phone.rand('10000000','99999999');
-            Cache::set('sendcode_'.$phone,$code,600);
+            Cache::set('sendcode_'.$phone, $code, 600);
             Cache::set('sendcode_handle_id'.$handle_id, $phone, 600);
+            log::record("send_message_again() set code => {handle_id: $handle_id \t code: $code \t phone: $phone \t}");
             return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'handle_id'=>$handle_id]);
         }catch(\Exception $e){
             return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
@@ -155,19 +170,36 @@ class Login extends Controller
     public function check_code()
     {
         try{
-            $param = $_REQUEST['param'];
-            Verify::loginCheck($param);
-            $sessionid = UUIDs::uuid16();
-            log::record($sessionid);
             log::record($_REQUEST);
+            $param = $_REQUEST['param'];
+            if(isset($param['handle_id']) || isset($param['code'])) {
+                return json_encode(['status'=>'fail','code'=>'2003','msg'=>'系统错误 not find handle id or code']);
+            }
             $handle_id = $param['handle_id'];
-            $phone = Cache::get('sendcode_handle_id'.$handle_id);
             $code = $param['code'];
+            if(empty($handle_id) || empty($code)) {
+                return json_encode(['status'=>'fail','code'=>'2004','msg'=>'handle id or code is null or empty']);
+            }
+
+            // 获取 phone
+            if(!Cache::has('sendcode_handle_id'.$handle_id)) {
+                return json_encode(['status'=>'fail','code'=>'2002','msg'=>'操作过时,请重新登录']);
+            }
+            $phone = Cache::get('sendcode_handle_id'.$handle_id);
+
+            if(!Cache::has('sendcode_'.$phone)) {
+                return json_encode(['status'=>'fail','code'=>'2002','msg'=>'操作过时,请重新登录']);
+            }
             $check_code = Cache::get('sendcode_'.$phone);
+
             if(!empty($check_code) && $code != $check_code) {
                 return json_encode(['status'=>'fail','code'=>'0090','msg'=>' 错误的验证码']);
             }
 
+            log::record("check_code() params => {handle_id: $handle_id \t code: $code \t phone: $phone \t check_code: $check_code }");
+            $sessionid = UUIDs::uuid16();
+            log::record($sessionid);
+
             //医生信息
             $info = DB::table('doctors')->where('phone',$phone)->field('is_send_message,is_admin,message_push,id,exam_class,attachment,username,password,login_time,login_failure,realname,email,phone,doctor_title,institution_id,department_id,doctor_role,is_report')->find();
             log::record($info);