Auth\Db::add_user(): add check of username uniqueness
This commit is contained in:
parent
b33a3e8205
commit
d42a864901
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(
|
||||
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