At the end of the work done, we just need to send an SMS and record the successful verification.
First, we check that this is really a phone number, and not an empty field:
if (!empty(Tools::getValue('phone')) && Validate::isPhoneNumber(Tools::getValue('phone')))
Then we will check for the existence of the phone number in the database:
Db::getInstance()->getValue('SELECT EXISTS
(SELECT phone FROM '.DB_PREFIX.'customer
WHERE phone = '.(int)Tools::getValue('phone').')')
Once all the conditions have been met, we send an SMS and write the generated code in a cookie for further comparison:
It doesn't matter which service you use - as soon as you send the SMS, enter the code in the verification_number field and send it to the address / login? Action = compare_code. To do this, respectively, you need to add a parameter check in the phoneVerification () method
action = compare_code:
if (Tools::getValue('action') == 'compare_code') {
and write our function to send the confirmation code:
$.ajax({
type: "POST",
headers: {"cache-control": "no-cache"},
async: true,
cache: false,
url: '/login?action=compare_code',
data:'code_verification='+$('input[name="verification_number"]').val(),
dataType: "json",
It remains to check the code and write down that the phone is confirmed, where exactly it is shown below, on the screenshot:
You can record a successful comparison by creating a field in the customer table called is_verification and adding a line of code to the Customer.php override file:
'is_verification' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
After that, we will need to add an additional field to the redefinition file:
$format['is_verification'] = (new FormField)
->setName('is_verification')
->setType('hidden')
->setValue(0)
;
In case of successful verification, it will write a flag to this user about the successful confirmation of the phone number.
That's all for us. Have a nice day and success in your work!