The user model can validate usernames

This commit is contained in:
Alex Tselegidis 2021-12-18 18:55:42 +01:00
parent f0992fd4f6
commit f58d3b142b

View file

@ -417,4 +417,22 @@ class Users_model extends EA_Model {
{ {
// Users do not currently have any related resources. // Users do not currently have any related resources.
} }
/**
* Validate the username.
*
* @param string $username Username.
* @param int|null $user_id Exclude user ID.
*
* @return bool Returns the validation result.
*/
public function validate_username(string $username, int $user_id = NULL): bool
{
if ( ! empty($user_id))
{
$this->db->where('id_users !=', $user_id);
}
return $this->db->get_where('user_settings', ['username' => $username])->num_rows() === 0;
}
} }