Jump to content

Block a new registration with an existing phone number


dbbrito

Recommended Posts

I wrote the hook for you now and I tested it as well

 

<?php
/**
 * Prevent Users Use phone that number already resigeted with another user
 * @package     WHMCS
 * @author      AladdinJ
 */

use WHMCS\Database\Capsule;

add_hook('ClientDetailsValidation', 1, function($vars) {
    
    $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
    $phonenumber = str_replace(' ', '', $phonenumber);
  
    $client = Capsule::table('tblclients')->whereRaw("REPLACE(`phonenumber`, ' ', '') = ? ", $phonenumber)->first();

    // in case of register
    if ($vars["register"] == "true")
    {
        if ($client) return ['Phone number already registered'];
    }
    
    
    // in case of update deatils
    else {
    $userid= $client->id;
        
        if ($client)
        {
            if ($vars["userid"] =! $userid )
            return ['Phone number already registered'];
        }
    }
});

 

Edited by AladdinJ
Link to comment
Share on other sites

Hello AladdinJ, here on my whmcs 8.6.1 it didn't work, I went to register and informed a phone that already existed, and it lets it go to the next field and does not inform that it has already been used, did I do something wrong? Whmcs writes to the database as follows: +55.35 96342-3173
Thank you very much

Edited by dbbrito
Link to comment
Share on other sites

I think that is because of the dash -

<?php
/**
 * Prevent Users Use phone that number already resigeted with another user
 * @package     WHMCS
 * @author      AladdinJ
 */
use WHMCS\Database\Capsule;

add_hook('ClientDetailsValidation', 1, function($vars) {
    $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
    $phonenumber = str_replace(' ', '', $phonenumber);
    $phonenumber = str_replace('-', '', $phonenumber);
  
    $client = Capsule::table('tblclients')->whereRaw("REPLACE(REPLACE(`phonenumber`, '-', ''), ' ', '')", $phonenumber)->first();
  
    // in case of register
    if ($vars["register"] == "true") if ($client) return ['Phone number already registered'];
    
    // in case of update deatils
    else {
    $userid= $client->id;
        if ($client) if ($vars["userid"] =! $userid ) return ['Phone number already registered'];
    }
});

 

I have edited the code , can you try now please
and tell me if it workes
 

Edited by AladdinJ
Link to comment
Share on other sites

i fexed some issues and just tested it and worked for me

 

<?php
/**
 * Prevent Users Use phone that number already resigeted with another user
 * @package     WHMCS
 * @author      AladdinJ
 */
use WHMCS\Database\Capsule;

add_hook('ClientDetailsValidation', 1, function($vars) {
    $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
    $phonenumber = str_replace(' ', '', $phonenumber);
    $phonenumber = str_replace('-', '', $phonenumber);
    $client = Capsule::table('tblclients')->whereRaw("REPLACE(REPLACE(`phonenumber`, '-', ''), ' ', '') = ?", [$phonenumber])->first();
  
    // in case of register
    if ($vars["register"] == "true") 
    {
        if ($client) {
            return ['Phone number already registered'];
        }
        
    }
    
    // in case of update deatils
    else {
    $userid= $client->id;
        if ($client)
        { 
           if ($vars["userid"] =! $userid ) return ['Phone number already registered'];
        }
    }
});


try and tell me if you still have problems 

Edited by AladdinJ
Link to comment
Share on other sites

you are right , just tested creating account using checkout , that is right the hook not fired 

this seems to be a BUG in WHMCS we need to report that to them to just make the hook fired even when create account using checkout 

if you can open support ticket to WHMCS

and I will try to fix this with additon hook , I will tell you if reached to solution 

Edited by AladdinJ
Link to comment
Share on other sites

Hello @dbbrito
I reached to solution for checkout registeration also

add_hook('ShoppingCartValidateCheckout', 1, function($vars) {
    
    if ($vars['custtype']== "new")
    {
        $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
        $phonenumber = str_replace(' ', '', $phonenumber);
        $phonenumber = str_replace('-', '', $phonenumber);
        $client = Capsule::table('tblclients')->whereRaw("REPLACE(REPLACE(`phonenumber`, '-', ''), ' ', '') = ?", [$phonenumber])->first();
        if ($client) return ['Phone number already registered'];
    }

});

condisder use the both hooks so that client can't register in exist phone number in any way

tell me if this works with you

Thanks

Edited by AladdinJ
Link to comment
Share on other sites

<?php
/**
 * Prevent Users Use phone that number already resigeted with another user
 * @package     WHMCS
 * @author      AladdinJ
 */
if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

use WHMCS\View\Menu\Item as MenuItem;
use WHMCS\Database\Capsule;

add_hook('ClientDetailsValidation', 1, function($vars) {
    $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
    $phonenumber = str_replace(' ', '', $phonenumber);
    $phonenumber = str_replace('-', '', $phonenumber);
 
    $client = Capsule::table('tblclients')->whereRaw("REPLACE(REPLACE(`phonenumber`, '-', ''), ' ', '') = ?", [$phonenumber])->first();

    // in case of register
    if ($vars["register"] == "true") 
    {
        if ($client) return ['Phone number already registered'];
    }

    // in case of update deatils
    else {
        $cli = Menu::context('client');
        if (!is_null($cli))
        {
            if ($client)
            {
                $thephoneclient = $client->id;
                $thecurrentclient = $cli->id;
                if ($thephoneclient != $thecurrentclient ) return ['Phone number already registered'];
            }
        }
    }
});

add_hook('ShoppingCartValidateCheckout', 1, function($vars) {
    
    if ($vars['custtype']== "new")
    {
        $phonenumber = '+'.$vars['country-calling-code-phonenumber'].".".$vars['phonenumber'];
        $phonenumber = str_replace(' ', '', $phonenumber);
        $phonenumber = str_replace('-', '', $phonenumber);
        $client = Capsule::table('tblclients')->whereRaw("REPLACE(REPLACE(`phonenumber`, '-', ''), ' ', '') = ?", [$phonenumber])->first();
        if ($client) return ['Phone number already registered'];
    }
});

this shoud work Inshallah  😍 don't forget to giva me like if it worked with you ❤️

Edited by AladdinJ
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated