Fix username verification on insert/update (#3239)

This commit is contained in:
Jeroen Peelaerts
2021-08-07 01:22:18 +02:00
committed by jekkos
parent 85f577556e
commit 4c3f6e4c31
3 changed files with 9 additions and 14 deletions

View File

@@ -60,6 +60,7 @@ class Employees extends Persons
$person_info->$property = $this->xss_clean($value);
}
$data['person_info'] = $person_info;
$data['employee_id'] = $employee_id;
$modules = array();
foreach($this->Module->get_all_modules()->result() as $module)
@@ -191,9 +192,9 @@ class Employees extends Persons
}
}
public function check_username()
public function check_username($employee_id)
{
$exists = $this->Employee->username_exists($this->input->get('username'));
$exists = $this->Employee->username_exists($employee_id, $this->input->get('username'));
echo !$exists ? 'true' : 'false';
}
}

View File

@@ -18,10 +18,11 @@ class Employee extends Person
return ($this->db->get()->num_rows() == 1);
}
public function username_exists($username)
public function username_exists($employee_id, $username)
{
$this->db->from('employees');
$this->db->where('employees.username', $username);
$this->db->where('employees.person_id <>', $employee_id);
return ($this->db->get()->num_rows() == 1);
}

View File

@@ -209,17 +209,10 @@ $(document).ready(function()
last_name: 'required',
username:
{
<?php
if($person_info->person_id == "")
{
?>
remote: '<?php echo site_url("$controller_name/check_username")?>',
<?php
}
?>
required: true,
minlength: 5
required: true,
minlength: 5,
remote: '<?php echo site_url("$controller_name/check_username/$employee_id")?>'
},
password:
{
@@ -270,4 +263,4 @@ $(document).ready(function()
}
}, form_support.error));
});
</script>
</script>