Show Posts


Messages - teppyogi

Pages: [1]
1
Ok, I was able to figure it out by exploring some of the AbanteCart code... Here is what I did, not sure if it is a "best practice" or if things are ugly but so far it seems to work:
Quote
<?php
$root_path = dirname(__FILE__);
if (defined('IS_WINDOWS')) {
    $root_path = str_replace('\\', '/', $root_path);
}
define('DIR_ROOT', $root_path);

// HTTP
$dirname = rtrim(dirname($_SERVER['PHP_SELF']), '/.\\');
$dirname = strip_tags(html_entity_decode($dirname, ENT_QUOTES, 'UTF-8'));
define('HTTP_SERVER', 'http://'.$_SERVER['HTTP_HOST'].$dirname);
define('HTTP_ABANTECART', 'http://'.$_SERVER['HTTP_HOST'].trim($dirname, 'static_pages'));

// DIR
define('DIR_APP_SECTION', str_replace('\'', '/', realpath(dirname(__FILE__))).'/');
define('DIR_CORE', str_replace('\'', '/', realpath(dirname(__FILE__).'/../')).'/core/');
define('DIR_ABANTECART', str_replace('\'', '/', realpath(DIR_APP_SECTION.'../')).'/');

// Startup
//~ require_once(DIR_ABANTECART.'system/config.php');
//~ require_once(DIR_CORE.'helper/utils.php');
//~ require_once(DIR_CORE.'lib/session.php');

//For some reason, the above directories are not populated on my server, so I hard code them below:
require_once('/mydomain_path/system/config.php');
require_once('/mydomain_path/core/helper/utils.php');
require_once('/mydomain_path/core/lib/session.php');

$from_admin = false;

$session_id = '';
if (isset($_GET['mode']) && $_GET['mode'] == 'admin') {
    $from_admin = true;
}

foreach (array_keys($_COOKIE) as $key) {
    if ($from_admin === true && preg_match("/^AC_CP/", $key)) {
        $session_id = $key;
        break;
    }
    if ($from_admin !== true && preg_match("/^AC_SF/", $key)) {
        $session_id = $key;
        break;
    }
}

define('SESSION_ID', $session_id);

//try to start session.
$session = new ASession(SESSION_ID);

$customerId = 0;
if ((isset($_SESSION['user_id']) || isset($_SESSION['customer_id']))){
  $customerId = $session->data['customer_id'];
}
?>

<!DOCTYPE html>
<html>
<body>
<?php
echo "hello, the logged in customer_id is: " . $customerId . ".";
?>
</body>
</html>

(sorry, for some reason I cannot seem to post "code" in the forum)

2
So I tried this, but the response is empty. Here is my test.php code:

Quote
<?php
echo "hello, the logged in customer_id is: " . $_GET['customer_id'] . ".";
?>

I believe this would, in fact, get the customer_id if it were a GET parameter in the URL, am I correct? What I would like to get is the customer_id which is in the session, like in other bits of code I see: $this->session->data['customer_id']

I feel I'm close, but I still don't get it...

3
Thanks, I took a look at the php file and method you suggested, I'm afraid it's my turn to not be sure I understand :-)

I see a bunch of bits which look interesting in there (e.g. $this->request->get['customer_id']), but the problem is I don't know how my php code can instanciate the "$this". I am too much of a beginner with respect to MVC frameworks, so I am hoping to simply be able to "get the cookie / read it", perhaps using some premade AbanteCart functions, in order to know who is logged in.

This code would be on the same domain, at the root, so there would not be any cross-domain issues for retrieving the session information, if that was your question? So basically this is external code, but (I think) it still resides "inside" the session...

Hope this is more clear! Tepp

4
Thanks, I was not aware this was located in a unique spot, which is great! For those who are looking to do the same thing, here is what I did:
  • File to change: core/init.php
  • Change the line: define('EMAIL_REGEX_PATTERN', '/^[A-Z0-9._%-+]+@[A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,16}$/i');
  • The only modification I made to the original code is marked in red, above. I can confirm that doing this worked on my installation of AbanteCart (1.3.0).

This was simply adapted for accepting the plus (+) sign into an email address, which is a personal favorite feature of mine in email management. It is by no means an RFC compliant validator, as I have learned since that doing such a validator is both complex and limited in terms of how effective it is at weeding out bad inputs.

Thanks again for the help! Tepp

5
Hi again,

I wish to include, outside of the AbanteCart architecture, a php file which can provide information based on the customer_id, if one is logged in. I have found online that many extensions use the following call:
Quote
$this->session->data['customer_id']

However, this seems to be for certain components which inherit some class from the core, I imagine. What I would like to know is the simplest way to simply be able to retrieve that information without going through a formal "extension" or "plugin".

In other words: I would like to add a file test.php at the root of the domain which can retrieve the customer_id.

Is this possible or is a formal development of an extension the only way? Thanks !

Tepp

6
General Support / Email validation seems too restrictive vs RFC?
« on: May 05, 2021, 07:05:53 PM »
Hello,

I have tried to register into AbanteCart for testing purposes using myAddress+test1@gmail.com but got a validation error. Looking up validation rules, I stumbled on this post, in which a core developer mentions that the validation regexp is:
Quote
define('EMAIL_REGEX_PATTERN','/^[A-Z0-9._%-]+@[A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z]{2,16}$/i');

This would explain why I get a validation error, but I am surprised the validation is not done with respect to the RFC, which you can look up on Wikipedia at the Email_address entry (I cannot post the link)...

Argument: the case for avoiding such addresses can be made since, in fact, it bypasses the 1 account per person rule. However, allowing such cases for testing purposes seems worthwhile. Also, validation imho should be just that: making sure the field has been validly populated. I regularly pest at websites which forbid me to use + in addresses because it is super practical for email classification. Therefore I would like it if my website were to avoid being in this category :-)

Questions: am I missing a setting anywhere? If not, should this become a feature in a future version? and in the meantime, how can I provide my own validation regexp?

Thanks! Tepp.

Pages: [1]

Powered by SMFPacks Social Login Mod