dbbrito Posted December 9, 2022 Share Posted December 9, 2022 Hello friends, does anyone know if it is possible to block a new registration with an existing phone number, or is there a possibility to make a hook for this? Thanks 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 11, 2022 Share Posted December 11, 2022 (edited) 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 December 11, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 11, 2022 Author Share Posted December 11, 2022 (edited) 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 December 11, 2022 by dbbrito 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 11, 2022 Share Posted December 11, 2022 hello @dbbrito you should complete the all fields then click registeration at that point will appaer the message "Phone number already registered" have you tried this ? 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 11, 2022 Author Share Posted December 11, 2022 Yes, I just tested that way too and it didn't work, the registration went through normally. I thought that in the phone field itself he already gave the message and didn't even let him finish the registration. 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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 December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 I just tested again with the modification and it didn't work, it passed normally. 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 in mysql it writes +55.35 96342-3173 inside the admin it shows +55.35963423173 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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 December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 I just changed and tested again and it doesn't work, the registration goes through normally. You add the hook and have to restart apache or restart the server? 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 no need to restart apache just added the hook 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 I just found out what it is, you're testing it by registering, but I'm testing the registration at the checkout of the cart, so it doesn't work, is there a way to leave it validating both at signup and at checkout? 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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 December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 (edited) ok, I believe it's not a bug, some complement in the code that may be missing, maybe someone will help us and complement the code. thanks and regards. Edited December 12, 2022 by dbbrito 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) 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 December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 Now yes, congratulations!!!! Thank you very much AladdinJ 1 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 you're welcome. @dbbrito good luck 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 I found a problem, in the client area when editing does not work! 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) <?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 December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 Can I leave everything in a single file? 0 Quote Link to comment Share on other sites More sharing options...
AladdinJ Posted December 12, 2022 Share Posted December 12, 2022 (edited) 15 minutes ago, dbbrito said: Can I leave everything in a single file? yes of course , the last code I have sent you can leave it in single file. Edited December 12, 2022 by AladdinJ 0 Quote Link to comment Share on other sites More sharing options...
dbbrito Posted December 12, 2022 Author Share Posted December 12, 2022 ok, I left everything in a single file and it was 100%. Thanks and regards 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.