Jump to content

Edit History

ps8modules

ps8modules

Hi.

And have you considered using JavaScript and calling ajax functions?
In JavaScript, you can intercept the submit form call and send the text from the password field to your ajax file.

 

E.g.:

custom-javascript.js

$(document).ready(function() {
    /* register form */
    var isRegisterPage = $('#registration');
    var isRegisterForm = $('#customer-form');

    /* checkout form */
    var isCheckoutPage = $('#checkout');
    var isGuestForm = $('#checkout-guest-form');

    var okRegister = 0;

    if (isRegisterPage.length && isRegisterForm.length) {
        // OK, is register page
        okRegister = 1;
    }

    if (isCheckoutPage.length && isRegisterForm.length && isGuestForm.hasClass('active')) {
        // OK, is register page
        okRegister = 1;
    }

    // checkout register tab
    $('[href=#checkout-guest-form]').click(function () {
        okRegister = 1;
    });

    // checkout login tab
    $('[href=#checkout-login-form]').click(function () {
        okRegister = 0;
    });

    isRegisterForm.submit(function (e) {
        if (e.result == true && okRegister == 1) {
          var pwd = $('#field-password').val();
          var email = $('#field-email').val();
          afterPostSubmitForm(email, pwd);
        }
    });
});

function afterPostSubmitForm(email, pwd) {
    $.ajax({
        type: "POST",
        url: '/modules/my_module/ajax.php',
        data:'action=afterCreateAccount&email='+email+'&pwd='+pwd,
        success: function(data){
            if (data !== ''){
                // OK
            } 
        }
    });
}

 

ajax.php

// uncomment <?php
header("Access-Control-Allow-Origin: *");

include('../../config/config.inc.php');
include('../../init.php');

$module_name = 'my_module';

$token = pSQL(Tools::encrypt($module_name.'/ajax.php'));
$token_url = pSQL(Tools::getValue('token'));

$db = Db::getInstance();

$module = Module::getInstanceByName($module_name);
if ($token != $token_url || !Module::isInstalled($module_name)) {
    echo($module->l('AJAX error'));
}

if ($module->active && Tools::getValue('action') == 'afterCreateAccount' && Tools::getValue('email') && Tools::getValue('pwd')) {
    // OK, data exists
    $response = '';

    $email = Tools::getValue('email');
    $pwd = Tools::getValue('pwd') 
    
    // call function on my_module
    $response = $module->newRegisteredCustomer($email, $pwd);

    echo $response;
}

 

my-module.php

public function hookActionFrontControllerSetMedia($params)
{
    $pages = array('order', 'registration ');

    if (in_array($this->context->controller->php_self, $pages)) {
         $this->context->controller->addJs(_PS_MODULE_DIR_.$this->name.'/views/front/js/custom-javascript.js'); 
        $ajax = $this->context->shop->getBaseURL(true).'modules/'.$this->name.'/ajax.php?token='.Tools::encrypt($this->name.'/ajax.php'); 
        $jsDef = [
            'ajax_my_module' => $ajax,
        ];
        Media::addJsDef($jsDef);
    } 
}

/* my function called in ajax */
public function newRegisteredCustomer($email, $pwd)
{
    $db = Db::getInstance();

    $getCustomerByEmail = $db->getValue('SELECT id_customer FROM '._DB_PREFIX_.'customer WHERE email = '."'".$email."'");

    if ($getCustomerByEmail) {
        $customer = new Customer((int)$getCustomerByEmail);
        $plainPassword = $pwd;

        // your function call API
        $apiResponse = CustomAuthAPI::authenticateUser($customer);

        if ($apiResponse->success) {
            return true;
        } else {
            return false;
        }
            
    }
}

 

ps8modules

ps8modules

Hi.

And have you considered using JavaScript and calling ajax functions?
In JavaScript, you can intercept the submit form call and send the text from the password field to your ajax file.

 

E.g.:

$(document).ready(function() {
    /* register form */
    var isRegisterPage = $('#registration');
    var isRegisterForm = $('#customer-form');

    /* checkout form */
    var isCheckoutPage = $('#checkout');
    var isGuestForm = $('#checkout-guest-form');

    var okRegister = 0;

    if (isRegisterPage.length && isRegisterForm.length) {
        // OK, is register page
        okRegister = 1;
    }

    if (isCheckoutPage.length && isRegisterForm.length && isGuestForm.hasClass('active')) {
        // OK, is register page
        okRegister = 1;
    }

    // checkout register tab
    $('[href=#checkout-guest-form]').click(function () {
        okRegister = 1;
    });

    // checkout login tab
    $('[href=#checkout-login-form]').click(function () {
        okRegister = 0;
    });

    isRegisterForm.submit(function (e) {
        if (e.result == true && okRegister == 1) {
          var pwd = $('#field-password').val();
          var email = $('#field-email').val();
          afterPostSubmitForm(email, pwd);
        }
    });
});

function afterPostSubmitForm(email, pwd) {
    $.ajax({
        type: "POST",
        url: '/modules/my_module/ajax.php',
        data:'action=afterCreateAccount&email='+email+'&pwd='+pwd,
        success: function(data){
            if (data !== ''){
                // OK
            } 
        }
    });
}

 

ps8modules

ps8modules

Hi.

And have you considered using JavaScript and calling ajax functions?
In JavaScript, you can intercept the submit form call and send the text from the password field to your ajax file.

 

E.g.:

$(document).ready(function() {
    /* register form */
    var isRegisterPage = $('#registration');
    var isRegisterForm = $('#customer-form');

    if (isRegisterPage.length && isRegisterForm.length) {
        // OK, is register page
        isRegisterForm.submit(function (e) {
            if (e.result == true) {
              var pwd = $('#field-password').val();
              var email = $('#field-email').val();
              afterPostSubmitForm(email, pwd);
            }
        });
    }

    /* checkout form */
    var isCheckoutPage = $('#checkout');
    
    if (isCheckoutPage.length && isRegisterForm.length) {
        // OK, is register page
        isRegisterForm.submit(function (e) {
            if (e.result == true) {
              var pwd = $('#field-password').val();
              var email = $('#field-email').val();
              afterPostSubmitForm(email, pwd);
            }
        });
    }
});

function afterPostSubmitForm(email, pwd) {
    $.ajax({
        type: "POST",
        url: '/modules/my_module/ajax.php',
        data:'action=afterCreateAccount&email='+email+'&pwd='+pwd,
        success: function(data){
            if (data !== ''){
                // OK
            } 
        }
    });
}

 

×
×
  • Create New...