• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

  • Chevereto Support CLST

    Support response

    Support checklist

    • Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • Confirm that the server meets the System Requirements
    • Check for any available Hotfix - your issue could be already reported/fixed
    • Read documentation - It will be required to Debug and understand Errors for a faster support response

Bulk importer allow to make wrong usernames

Status
Not open for further replies.

Che

Chevereto Member
Bulk importer allow to create user with name, for example "user name one" (if username folder was "user name one") ... Sure, I understand that it is not right folder name but sometimes it happened. So after it you can't do anything with that user coz you can't open profile (the link has spaces). Maybe it's good idea to check it before creating?

Thanks
 
Maybe it's good idea to check it before creating?
The importer is an admin-only tool, is understood that you throw usable stuff (no weird folders and such).

Anyway, I will sanitize these.
 
  • Like
Reactions: Che
Thank you bring this to my attention, I've patched the user paser and now the importer will sanitize these folders. Here:

Code:
                                // By default we look for matching users...
                                $userLookup = true;
                                $username = basename($pathHandle);
                                $username_max_length = Settings::get('username_max_length');
                                $username_min_length = Settings::get('username_min_length');
                                // Replace spaces
                                $usernameClean = preg_replace('/\s+/', '_', $username);
                                // Get only \w
                                $usernameClean = preg_replace('/\W/', null, $usernameClean);
                                // Make sure to fullfill the limit
                                $usernameClean = substr($usernameClean, 0, $username_max_length);
                                // Add some padding
                                if(strlen($usernameClean) < $username_min_length) {
                                    $usernameClean .= '_' . G\random_string($username_min_length - $usernameClean);
                                }
                                // Folder name doesn't satisfy a valid username string
                                if($username != $usernameClean) {
                                    $this->logProcess("Username $username is invalid username string, switching to $usernameClean");
                                    // Don't look, just create a new user
                                    $userLookup = false;   
                                }
                                $parsed = array_merge([
                                    'username' => $username
                                ], $this->parsed);
                                // If username exists, assing its $content_id
                                if ($userLookup && $user = User::getSingle($username, 'username')) {
                                    $this->logProcess("Username $username already exists");
                                    $insertId = $user['id'];
                                // Update user based on parsed metadada $this->parsed
                                } else {
                                    // Make sure to insert a new user
                                    $u = 0;
                                    while (User::getSingle($usernameClean, 'username')) {
                                        $this->logProcess("Must try a different username as $usernameClean already exists");
                                        // It strips the number previously appended, so we get user1, user2, and so on.
                                        if($u > 0) {
                                            $usernameClean = G\str_replace_last($u, null, $usernameClean);
                                        }
                                        // Soon as this gets too big, we trim the last $usernameClean char
                                        if(strlen($usernameClean . $u) > $username_max_length) {
                                            $usernameClean = substr($usernameClean, 0, -1);
                                        }
                                        $u++;
                                        $usernameClean .= $u;
                                        $parsed['username'] = $usernameClean;
                                    }
                                    $this->logProcess("About to insert user $usernameClean");
                                    $insertId = User::insert($parsed);
                                    $this->logProcess("Username $usernameClean (id $insertId) inserted");
                                    $user = User::getSingle($insertId, 'id');
                                }
^ This will be added to the next revision.
 
  • Like
Reactions: Che
Status
Not open for further replies.
Back
Top