Quellcode durchsuchen

登录验证码

wzh vor 5 Jahren
Ursprung
Commit
a02bb6c313
2 geänderte Dateien mit 47 neuen und 1 gelöschten Zeilen
  1. 6 0
      api/application/config/response.php
  2. 41 1
      api/application/controllers/Common.php

+ 6 - 0
api/application/config/response.php

@@ -25,6 +25,9 @@ $config['response']['0101'] = '用户名或密码错误';
 $config['response']['0102'] = '用户不存在';
 $config['response']['0103'] = '账户已被停用,请联系管理员';
 $config['response']['0104'] = '同级用户不能修改账户状态';
+$config['response']['0105'] = '请输入验证码';
+$config['response']['0106'] = '验证码已经过期';
+$config['response']['0107'] = '验证码错误';
 //项目 0200-0299
 $config['response']['0200'] = '项目id不能为空';
 $config['response']['0201'] = '项目编号已存在';
@@ -183,6 +186,9 @@ $config['response_en']['0101'] = 'Wrong user name or password';
 $config['response_en']['0102'] = 'user does not exist';
 $config['response_en']['0103'] = 'The account has been deactivated. Please contact the administrator';
 $config['response_en']['0104'] = 'Account status cannot be modified by users of the same level';
+$config['response_en']['0105'] = 'Please enter the verification code';
+$config['response_en']['0106'] = 'The verification code has expired';
+$config['response_en']['0107'] = 'Verification code error';
 //项目 0200-0299
 $config['response_en']['0200'] = 'Item ID cannot be empty';
 $config['response_en']['0201'] = 'Project number already exists';

+ 41 - 1
api/application/controllers/Common.php

@@ -10,7 +10,7 @@ class Common extends CI_Controller {
         parent::__construct();
         $this->load->model('User_model');
         $this->response = $this->config->config['response_en'];
-        
+
         $version = 1;
         $this->session->set_userdata('version', $version);
         $this->version = $version;
@@ -27,6 +27,10 @@ class Common extends CI_Controller {
         if(empty($client_key)) exit(json_result('0003', $this->response['0003']));
         if(empty($username) || empty($password)) exit(json_result('0100', $this->response['0100']));
         $password = md5($password);
+        
+        if(empty($os) && empty($code)) exit(json_result('0105', $this->response['0105']));
+        if (empty($os) && !isset($_SESSION['login_code'])) exit(json_result('0106',$this->response['0106']));
+        if (empty($os) && $_SESSION['login_code'] != $code) exit(json_result('0107',$this->response['0107']));
 
         $user = $this->User_model->get_one(array('username'=>$username,'role'=>$role));
         if(!empty($user)) {
@@ -153,6 +157,42 @@ class Common extends CI_Controller {
         exit(json_result('0000', $this->response['0000'], ['list'=>$data]));
     }
 
+    public function get_code_image(){
+        $type = intval($this->input->post('type',true));
+
+        $this->load->helper('captcha');
+
+        if (!file_exists('../upload')) mkdir('../upload');
+        if (!file_exists('../upload/image')) mkdir('../upload/image');
+        if (!file_exists('../upload/image/code')) mkdir('../upload/image/code');
+        $url = '/upload/image/code';
+        $code = rand(1000,9999);
+        $vals = array(
+            'word'      => $code,
+            'img_path'  => '../upload/image/code/',
+            'img_url'   => $url,
+            'img_width' => 120,
+            'font_path' => '../file/font/PingFangRegular.ttf',
+            'img_height'    => 36,
+            'expiration'    => 600,
+            'word_length'   => 4,
+            'font_size' => 20,
+            'img_id'    => 'Imageid',
+        );
+        
+        $cap = create_captcha($vals);
+        $filename = $cap['filename'];
+        $url .= '/'.$filename;
+        $this->load->library('session');
+        if ($type == 0) {
+            $this->session->set_userdata('login_code', $code);
+        }else {
+            $this->session->set_userdata('password_code', $code);
+        }
+
+        exit(json_result('0000',$this->response['0000'],array('path'=>base_url($url))));
+    }
+
 
     // 批量导入
     function test(){