diff --git a/src/application/controllers/backend_api.php b/src/application/controllers/backend_api.php index e7afd06d..fafe8bf3 100644 --- a/src/application/controllers/backend_api.php +++ b/src/application/controllers/backend_api.php @@ -850,8 +850,13 @@ class Backend_api extends CI_Controller { */ public function ajax_validate_username() { try { - // We will use the function in the admins_model because it is sufficient for - // the rest user types for now (providers, secretaries). + // $_POST['record_exists'] is treated like a string in this method and this + // is making the validation algorithm fail. So we need to convert the value + // into bool before validating the username. + $_POST['record_exists'] = ($_POST['record_exists'] == 'true') ? TRUE : FALSE; + + // We will only use the function in the admins_model because it is sufficient + // for the rest user types for now (providers, secretaries). $this->load->model('admins_model'); $is_valid = $this->admins_model->validate_username($_POST['username'], $_POST['record_exists']); echo json_encode($is_valid); diff --git a/src/application/models/admins_model.php b/src/application/models/admins_model.php index ced992f7..ca249818 100644 --- a/src/application/models/admins_model.php +++ b/src/application/models/admins_model.php @@ -357,10 +357,11 @@ class Admins_Model extends CI_Model { */ public function validate_username($username, $record_exists) { $num_rows = $this->db->get_where('ea_user_settings', array('username' => $username))->num_rows(); - if (($num_rows == 0 && $record_exists == FALSE) || ($num_rows == 1 && $record_exists == TRUE)) { - return TRUE; + if (($num_rows == 0 && $record_exists == FALSE) || ($num_rows == 1 && $record_exists == TRUE) + || ($num_rows == 0 && $record_exists == TRUE)) { + return TRUE; // valid } else { - return FALSE; + return FALSE; // not valid } } } diff --git a/src/application/views/backend/users.php b/src/application/views/backend/users.php index 886ef5a8..b3ef5f41 100644 --- a/src/application/views/backend/users.php +++ b/src/application/views/backend/users.php @@ -1,5 +1,13 @@ + + + + +