New user bug?

I think I've found a bug:

When a WHMCS user registers a new site on WordPress, if that user doesn't already have a WordPress site, the plugin will create a new user.

It does this by taking the WHMCS users email address and uses the portion of the address prior to the '@'.

But I'm encountering a problem with this!

If I register a site having logged into WHMCS as stephen@domainA.com and create a site, I'm issued a WordPress username of 'stephen'. That's all good so far.

But if I then log into WHMCS as stephen@domainB.com and create a second site, the plugin fails.

It appears the plugin fails to spot that it cannot register 'stephen' again (because it's a different email address). I end up with a 'pending' order, which when I look at it, it has a blank username.

    Kimberly

    Hey there!

    If you check out the usage page for the provisioning plugin you will find

    == Known Issues ==

    1. If a user does not already exist on WordPress as determined by matching the WHMCS Clients email with the WordPress users email, a new user will be created using the WHMCS Client’s email address and the portion before the ‘@’ as the users name. If you are Accepting Orders in Admin before creation you can change the default username there. Once the username is created it cannot be changed.

    stephenb

    Yep, have seen and understand that.

    But what I'm saying is the plugin actually fails (it generates an error in WHMCS) if stephen@domainB.com registers after stephen@domainA.com has already registered because the plugin tries to register a username that already exists.

    In other words, the plugin is missing any sort of error detection to make sure that the user it's about to try and create doesn't already exist. It's smart enough to make sure it doesn't register the same email address twice, so really it ought to check for duplicate usernames as well.

    It would be more normal for the plugin to detect that the user already exists and check for the existence of something like stephen01 instead.

    maxaud

    Looks like this is generated at \whmcs-multisite-provisioning\whmcs\modules\servers\whmcs_multisite\whmcs_multisite.php:

    // Default Wordpress user name everything before the @ in their whmcs email
    	$wp_user_name = explode('@',$clientsdetails['email']);
    	$wp_user_name = $wp_user_name[0];

    The username_exists function can be used if WordPress is being loaded here. Alternatively, you can do rand(1000000,9999999) to get a 7 digit random number to append (there's also uniqid() but it's 13 chars).

    Arnold

    Your right but working on the wrong end. It does check but the piece on the plugin that extracted the username wasn't working right, It tries to match the email address first and if that doesn't work it tries to create a new user. If the user name already exist it tacks a number on and tries again until it finds an empty spot.

    Try the attached version and see if it solves it for you.

    stephenb

    My MultiUser site is called demo.epage.co.uk

    Create first user who's email address is stephen@DomainA.com. Creating a subsite called sept28 That all works fine:

    Request:
    whmcs%5Baction%5D=create&whmcs%5Bdomain%5D=sept28&whmcs%5Buser_name%5D=stephen&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=stephen%40DomainA.com&whmcs%5Blast_name%5D=Bennett&whmcs%5Bfirst_name%5D=Stephen&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=30&whmcs%5Bcredentials%5D%5Buser_login%5D=Administrator&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=14&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=56&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=10

    Response:
    Array

    (
        [user_name] => stephen
        [install_type] => subdomain
        [domain] => sept28.demo.epage.co.uk
        [path] => /
        [login] => stephen
        [blog_id] => 25
        [success] => 1
    )

    Next, the second user tries to create a subsite called sept28b using the email address: stephen@DomainB.com. This is where things fall apart. You can see that the request below is attempting to add the user 'stephen' once again, but this fails:

    Request:
    whmcs%5Baction%5D=create&whmcs%5Bdomain%5D=sept28b&whmcs%5Buser_name%5D=stephen&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=stephen%40DomainB.com&whmcs%5Blast_name%5D=Bennett&whmcs%5Bfirst_name%5D=Stephen&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=30&whmcs%5Bcredentials%5D%5Buser_login%5D=Administrator&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=1&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=57&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=10

    Response:

    Array
    (
        [0] =>
        [1] => Array
            (
                [url] => http://demo.epage.co.uk
                [content_type] =>
                [http_code] => 0
                [header_size] => 0
                [request_size] => 822
                [filetime] => -1
                [ssl_verify_result] => 0
                [redirect_count] => 0
                [total_time] => 30.03
                [namelookup_time] => 0
                [connect_time] => 0
                [pretransfer_time] => 0
                [size_upload] => 570
                [size_download] => 0
                [speed_download] => 0
                [speed_upload] => 18
                [download_content_length] => -1
                [upload_content_length] => 570
                [starttransfer_time] => 0
                [redirect_time] => 0
                [certinfo] => Array
                    (
                    )
    
                [redirect_url] =>
            )
    
        [2] => Connection Error: 28 - Operation timed out after 30030 milliseconds with 0 bytes received
    )
    Arnold

    I'm getting an entirely different pattern. When the order is placed the user name created is the first 7characters of the domain name with a number tacked on. This is done on the WHMCS side so the plugin accepts what is sent.

    whmcs%5Baction%5D=create&whmcs%5Bmapped_domain%5D=firstsite.wpwhmcs.com&whmcs%5Bdomain%5D=firstsite&whmcs%5Btitle%5D=My+Blog&whmcs%5Buser_name%5D=firstsi1&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=bryant%40gmail.com&whmcs%5Blast_name%5D=Bailey&whmcs%5Bfirst_name%5D=Bryant&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=10&whmcs%5Bcredentials%5D%5Buser_login%5D=arky&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=1&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=9&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=1

    Response

    Array
    (
        [user_name] => firstsi1
        [install_type] => subdomain
        [domain] => firstsite.wpwhmcs.com
        [path] => /
        [login] => firstsi1
        [blog_id] => 8
        [success] => 1
    )

    Second try

    whmcs%5Baction%5D=create&whmcs%5Bmapped_domain%5D=secondsite.wpwhmcs.com&whmcs%5Bdomain%5D=secondsite&whmcs%5Btitle%5D=My+Blog&whmcs%5Buser_name%5D=seconds1&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=bryant%40webwrights.com&whmcs%5Blast_name%5D=Bailey&whmcs%5Bfirst_name%5D=Bryant&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=10&whmcs%5Bcredentials%5D%5Buser_login%5D=arky&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=2&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=10&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=1

    Response

    Array
    (
        [user_name] => seconds1
        [install_type] => subdomain
        [domain] => secondsite.wpwhmcs.com
        [path] => /
        [login] => seconds1
        [blog_id] => 9
        [success] => 1
    )

    Everything works.

    It's true we try to make a user id out of the email address, but since it's a field that can be set by WHMCS we use it if it's there. So I'm wondering why your WHMCS isn't doing the same. What version are you running?

    Arnold

    I'm getting an entirely different pattern. When the order is placed the user name created is the first 7characters of the domain name with a number tacked on. This is done on the WHMCS side so the plugin accepts what is sent.

    whmcs%5Baction%5D=create&whmcs%5Bmapped_domain%5D=firstsite.wpwhmcs.com&whmcs%5Bdomain%5D=firstsite&whmcs%5Btitle%5D=My+Blog&whmcs%5Buser_name%5D=firstsi1&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=bryant%40gmail.com&whmcs%5Blast_name%5D=Bailey&whmcs%5Bfirst_name%5D=Bryant&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=10&whmcs%5Bcredentials%5D%5Buser_login%5D=arky&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=1&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=9&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=1

    Response

    Array
    (
        [user_name] => firstsi1
        [install_type] => subdomain
        [domain] => firstsite.wpwhmcs.com
        [path] => /
        [login] => firstsi1
        [blog_id] => 8
        [success] => 1
    )

    Second try

    whmcs%5Baction%5D=create&whmcs%5Bmapped_domain%5D=secondsite.wpwhmcs.com&whmcs%5Bdomain%5D=secondsite&whmcs%5Btitle%5D=My+Blog&whmcs%5Buser_name%5D=seconds1&whmcs%5Bpassword%5D=********&whmcs%5Bemail%5D=bryant%40webwrights.com&whmcs%5Blast_name%5D=Bailey&whmcs%5Bfirst_name%5D=Bryant&whmcs%5Bdefault_role%5D=administrator&whmcs%5Bupload_space%5D=10&whmcs%5Bcredentials%5D%5Buser_login%5D=arky&whmcs%5Bcredentials%5D%5Buser_password%5D=********&whmcs%5Bcredentials%5D%5Bremember%5D=0&whmcs%5Bcredentials%5D%5Bwhmcs_client_id%5D=2&whmcs%5Bcredentials%5D%5Bwhmcs_service_id%5D=10&whmcs%5Bcredentials%5D%5Bwhmcs_product_id%5D=1

    Response

    Array
    (
        [user_name] => seconds1
        [install_type] => subdomain
        [domain] => secondsite.wpwhmcs.com
        [path] => /
        [login] => seconds1
        [blog_id] => 9
        [success] => 1
    )

    Everything works.

    It's true we try to make a user id out of the email address, but since it's a field that can be set by WHMCS we use it if it's there. So I'm wondering why your WHMCS isn't doing the same. What version are you running?

    stephenb

    I'm using Version: 5.1.2 plus the various patches that have been supplied in the forums.

    I see your requests look sightly different to mine as well. It looks like you've created your sites above using a mapped domain. If I do that, all works...

    In other words, if I create a site with the 'Require Domain' option selected and create a site with the domain, lets say 'test28c.com' all works fine. Even when using the account belonging to stephen@DomainB.com a WordPress user is created called 'testccom' (instead of trying to re-create 'stephen' again).

    I only have a problem on this 'demo' setup which doesn't allow mapped domains as these sites only last 14 days before WHMCS is set to terminate them.