Auth\Db::add_user(): add check of username uniqueness
This commit is contained in:
parent
e2dca482b3
commit
2ee5c7540b
1 changed files with 16 additions and 5 deletions
|
@ -138,18 +138,29 @@ class Db extends Backend {
|
|||
*/
|
||||
public static function add_user($info) {
|
||||
$values = [
|
||||
App::get('auth.db.username_field') => $info['username'],
|
||||
App::get('auth.db.password_field') => password_hash(
|
||||
$info['password'],
|
||||
constant('PASSWORD_'.strtoupper(App::get('auth.db.password_hash_algo')))
|
||||
self :: $username_field => $info['username'] ?? null,
|
||||
self :: $password_field => (
|
||||
($info['password'] ?? null)?
|
||||
password_hash(
|
||||
$info['password'],
|
||||
constant('PASSWORD_'.strtoupper(App::get('auth.db.password_hash_algo')))
|
||||
):
|
||||
null
|
||||
),
|
||||
];
|
||||
foreach($info as $field => $value) {
|
||||
if (!$value) {
|
||||
Log :: error("add_user: field %s is missing", $field);
|
||||
Log :: error("add_user: field %s is missing (or null)", $field);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check username uniqueness
|
||||
if (self :: get_user($info['username'])) {
|
||||
Log :: error("add_user: a user with username %s already exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach(App :: get('auth.db.exposed_fields') as $field)
|
||||
if (isset($info[$field]) && $info[$field])
|
||||
$values[$field] = $info[$field];
|
||||
|
|
Loading…
Reference in a new issue