mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-01 04:12:22 +03:00
The user model can validate usernames
This commit is contained in:
parent
f0992fd4f6
commit
f58d3b142b
1 changed files with 22 additions and 4 deletions
|
@ -46,7 +46,7 @@ class Users_model extends EA_Model {
|
||||||
'notes' => 'notes',
|
'notes' => 'notes',
|
||||||
'roleId' => 'id_roles',
|
'roleId' => 'id_roles',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save (insert or update) a user.
|
* Save (insert or update) a user.
|
||||||
*
|
*
|
||||||
|
@ -198,7 +198,7 @@ class Users_model extends EA_Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $this->db->get_where('users', ['id' => $user_id])->row_array();
|
$user = $this->db->get_where('users', ['id' => $user_id])->row_array();
|
||||||
|
|
||||||
$this->cast($user);
|
$this->cast($user);
|
||||||
|
|
||||||
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user_id])->row_array();
|
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user_id])->row_array();
|
||||||
|
@ -240,7 +240,7 @@ class Users_model extends EA_Model {
|
||||||
|
|
||||||
// Check if the required field is part of the user data.
|
// Check if the required field is part of the user data.
|
||||||
$user = $query->row_array();
|
$user = $query->row_array();
|
||||||
|
|
||||||
$this->cast($user);
|
$this->cast($user);
|
||||||
|
|
||||||
if ( ! array_key_exists($field, $user))
|
if ( ! array_key_exists($field, $user))
|
||||||
|
@ -278,7 +278,7 @@ class Users_model extends EA_Model {
|
||||||
foreach ($users as &$user)
|
foreach ($users as &$user)
|
||||||
{
|
{
|
||||||
$this->cast($user);
|
$this->cast($user);
|
||||||
|
|
||||||
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row_array();
|
$user['settings'] = $this->db->get_where('user_settings', ['id_users' => $user['id']])->row_array();
|
||||||
|
|
||||||
unset(
|
unset(
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue