wzh 5 år sedan
förälder
incheckning
25f7d6a418
1 ändrade filer med 30 tillägg och 18 borttagningar
  1. 30 18
      api/application/controllers/User.php

+ 30 - 18
api/application/controllers/User.php

@@ -152,9 +152,9 @@ class User extends Base_Controller{
             exit(json_result('0011', $this->response['0011'], array()));
         }
 		$data['name'] = $this->input->post('name',true);
-		$data['username'] = trim($this->input->post('account',true));
+		
 		$phone = $this->input->post('phone',true);
-		$data['password'] = $this->input->post('password',true);
+		
 		$email = $this->input->post('email',true);
 		$data['company'] = $this->input->post('company',true);
 		$avatar = $this->input->post('avatar',true);
@@ -173,14 +173,7 @@ class User extends Base_Controller{
 		// $data['zone'] = empty($zone) ? '' : $zone;
 		// 验证请求数据
 		$config = array();
-		$config[] = array(
-		        'field' => 'password',
-		        'label' => 'Password',
-		        'rules' => 'min_length[6]',
-		        'errors' => array(
-		            'min_length' => '0720',
-		        )
-		    );
+		
 		if(!empty($data['phone'])){
 			$config[] = array(
 				        'field' => 'phone',
@@ -202,15 +195,26 @@ class User extends Base_Controller{
 				        )
 				    );
 		}
-		if (!empty($config)) {
-			$this->load->library('form_validation');
-			$this->form_validation->set_rules($config);
-			if ($this->form_validation->run() == FALSE){
-				$errors = $this->form_validation->error_array();
-		        exit(json_result(current($errors),$this->response[current($errors)],array()));
-		    }
-		}
+		
 		if (empty($where['id'])) { // 添加用户
+			$data['username'] = trim($this->input->post('account',true));
+			$data['password'] = $this->input->post('password',true);
+			$config[] = array(
+		        'field' => 'password',
+		        'label' => 'Password',
+		        'rules' => 'min_length[6]',
+		        'errors' => array(
+		            'min_length' => '0720',
+		        )
+		    );
+			if (!empty($config)) {
+				$this->load->library('form_validation');
+				$this->form_validation->set_rules($config);
+				if ($this->form_validation->run() == FALSE){
+					$errors = $this->form_validation->error_array();
+			        exit(json_result(current($errors),$this->response[current($errors)],array()));
+			    }
+			}
 			if(!isset($data['username']) || $data['username'] == '') exit(json_result('0708',$this->response['0708'],array()));
 			if(mb_strlen($data['username']) > 20) exit(json_result('0723',$this->response['0723'],array()));
 			if (empty($data['password'])) {
@@ -244,6 +248,14 @@ class User extends Base_Controller{
 			$this->add_operation_log('insert',"Add user.User name:\"{$data['name']}\"",0,1);
 		}else{  // 编辑用户
 			unset($data['password']);
+			if (!empty($config)) {
+				$this->load->library('form_validation');
+				$this->form_validation->set_rules($config);
+				if ($this->form_validation->run() == FALSE){
+					$errors = $this->form_validation->error_array();
+			        exit(json_result(current($errors),$this->response[current($errors)],array()));
+			    }
+			}
 
 			// if ($this->User_model->getDataCount(array('username'=>$data['username']),$where['id'])) {
 			// 	exit(json_result('0706',$this->response['0706'],array()));