Is there a way to access Prestashop's Web service using a client's login credentials instead of a key?

Currently, I am delving into Prestashop's development and experimenting with creating a third-party application using react.js (specifically React Native). My goal is to retrieve Json data from the Prestashop webservice. However, my main focus is on allowing customers to login with their individual accounts only, while also enabling CRUD functionalities.

In advance, thank you for your patience and attention.

Best regards,

Michel Diz

Answer №1

If you are having trouble accessing Prestashop backoffice through login, it may be because webservices are not enabled and a key has not been generated. I suggest changing your approach to logging in. Keep in mind that customer accounts and webservices are not directly linked, as webservices are primarily used to access stored data in Prestashop's backoffice rather than the frontoffice.

Do you need specific instructions on how to enable webservices and generate a key?

I hope this information is helpful to you.

Answer №2

If you're still in need of a solution, there is actually a way.

ENSURE THAT THE LOGIN IS SECURE.

Given that access to all PrestaShop data is being granted, it's crucial to have a highly secure login system. By utilizing PHP, I was able to recreate it and believe that with some modifications, you can tailor it to meet your requirements. Consider this as a starting point.

In order to establish a login system using the PrestaShop webservice, you will require three key components:

1. Access to the customers table via the webservice 2. The COOKIE_KEY, as defined in app/config -> parameters.php: 'cookie_key' => '12321test'; 3. Proficiency in PHP The initial step involves obtaining the customers table from the webservice.

// code placeholder
require_once('./../PSWebServiceLibrary.php');

/**
 * Obtain information from PrestaShop
 */

$webService = new PrestaShopWebservice($url, $key, $debug);

$COOKIE_KEY = 'CookieKey';
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];

$optUser = array(
    'resource' => 'customers',
    'filter[email]' => '[' . $email . ']',
    'display' => '[id,email,lastname,firstname,passwd]'
);

$resultUser = ($webService->get($optUser));

$json = json_encode($resultUser);

The second and most critical step is validating the user input.

// code placeholder

foreach ($resultUser->customers->customer as $info) {
    // Prestashop uses the cookie_key along with a salt key for password verification. Utilize the PHP function password_verify() to validate the password.
    $salt = substr($info->passwd, strrpos($info->passwd, ':') + 1, 2);
    $ZCpassword = md5($COOKIE_KEY . $password) . ':' . $salt;

    // Verify if the passwords match
    if (password_verify($password, $info->passwd) == true) {
        session_start();
        $response = array();
        $response['status'] = 'success';
        $response['message'] = "Login successful!";
        setcookie("userId", $info->id);
        header('Content-type: application/json');
        echo json_encode($response);
    } else {
        $response = array();
        $response['status'] = 'error';
        $response['message'] = 'Invalid password';
        header('Content-type: application/json');
        echo json_encode($response);
    }
}

This serves as a blueprint to illustrate how to create a functional example.

Trust this provides assistance!

Answer №3

If you’re still on the hunt for this solution,

<?

if (isset($_GET["email"]) && isset($_GET["password"]) )
{
$email =  $_GET["email"];
$password = $_GET["password"];

$COOKIE_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$jsonurl = "https://<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="702828282828282828282828282828282828282828301508111d001c155e131f1d">[email protected]</a>/api/customers?filter[email]=".$email."&display=[passwd]&output_format=JSON";
$json = file_get_contents($jsonurl);
$json_a = json_decode($json, true);

$loopone = $json_a['customers'];
$looptwo = $loopone[0];
$loopthree = $looptwo['passwd'];

$ZCpassword = md5($COOKIE_KEY . $password);

if (strcmp($loopthree, $ZCpassword) == 0) {
        echo "success";
    } else {
         echo "failure";
    }

}
else
{
    echo "Provide a valid url parameter";
}

?>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a TypeScript generic type for the "pick" function to define the types of values in the resulting object

I am facing an issue while writing the type for the pick function. Everything works smoothly when picking only one key or multiple keys with values of the same type. However, if I attempt to pick a few keys and their values are of different types, I encoun ...

Can AJAX function properly when the server-side code is hosted on a separate domain?

After opening Firefox's scratchpad and inputting the following code... function ajaxRequest() { var xmlhttp; var domainName = location.host; var url = 'http://leke.dyndns.org/cgi/dn2ipa/resolve-dns.py?domainName='; url = url + domainName + ...

A simple way to deactivate a React component (or the onClick event itself) using the onClick event

I have come across similar inquiries, but unfortunately, none of the solutions provided seem to work in my particular scenario. I am hopeful that someone can shed some light on what might be causing the issue. In my ReactApp, there are 3 card components t ...

Encountering unexpected behavior with the .data() method

I'm encountering an issue with my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv= ...

How to add vertical bars within ng-repeat in AngularJS

I attempted to retrieve values from an array variable using ng-repeat within unordered lists. Although the values are displaying correctly and everything is functioning properly, I added vertical bars after each value to represent sub-categories on my page ...

Are there alternative methods, aside from using a computed property, that can be utilized to store a Vue route parameter in a way where

In my Vue component, I am working on passing a route parameter through XHR requests and potentially using it in other areas as well. Initially, I considered storing it as a data attribute but realized that it could be modified by someone. Then it occurred ...

What is the most effective way to manage and respond to multiple events while also organizing the overall structure of

I am currently in the process of planning a complex web application using WebGL and Three.js. As I experiment with different tests, I have encountered a problem that is raising many questions for me. I am unsure of the correct approach to take and would gr ...

The web server is serving an HTML file instead of the expected JSON response

Is there a way to extract the JSON data from ? I have tried using AJAX but it only retrieves the entire HTML page instead. $.ajax({ url: 'http://www.bartdekimpe.be/anoire/index.php/admin/getGamesUserJson/34', success: function(data) { ...

Searching through text in Node JS using Mongoose for Full-Text queries

I am facing an issue while attempting to perform a full-text search on an array of strings using Mongoose. The error message I receive is as follows: { [MongoError: text index required for $text query] name: 'MongoError', message: 'text ...

Using a three.js texture with a JSON object

Currently, I am working on a customization project where I am using three.js to export an HTML5 canvas as a 3D preview. My goal is to have the texture placed only on the front side, but it seems to appear on all sides instead. This is the code I am using: ...

Sorting and dividing an Array using Angular

Forgive me in advance if this sounds like a naive question, as Angular and Typescript are not my strong suits. I am assisting a friend with an issue that I can't seem to overcome. I have an array of players that includes details such as first name an ...

What is the issue with the character set?

Attempting to send request data from JavaScript to Java using JSON format. In JavaScript, the request body appears as: { "id": "3", "name": "Chicken pasta", "description": "Lets make chicken pasta", "category": "Unassigned", "favorite" ...

Trouble with Next.js App Router OG Image not appearing after deployment

I am facing an issue with my Nextjs project that uses the app router. Inside the app directory, there is a file named opengraph-image.png. I have set this file to be the OG Image for the landing page, but after deploying and checking, the OG image does not ...

Monitor and adjust variables simultaneously using AngularJS

My goal is to dynamically calculate and display values based on two other variables in real time. I've successfully managed to track one variable, but not both simultaneously. $scope.color_slider_bar = { value:0, minValue: 0, maxValue: ...

Switching Image Values in JavaScript: A Quick Guide

After successfully using a JavaScript function to swap the src of two images, I encountered an issue. I also needed to switch two values associated with the images so that I could calculate them later. For example: img src="ble.jpg" id="F" value="" onclic ...

The compatibility between Node JS and Vue JS front-end seems to be glitchy and

I am currently developing a Node JS backend application and Vue JS front-end. In order to authenticate users, I need to implement sessions in the API. For my backend server, I am using the following components: express (4.18.2) express-session (1.17.3) c ...

Show only half of the Google Charts

I have a code snippet that displays a chart with dimensions of 500x500. However, I only want to show half of the chart, like 500x250. But whenever I adjust the values in the div, it resizes the entire chart instead of just showing half. My goal is to hide ...

What is the best way to navigate a dynamic table in Vue.js?

I'm currently working on creating dynamic tables in Vue using loops where users can upload a table and view it. <el-table :data="filtered" border style="width: 100%" height="500" @selection-change="handleSelectio ...

TypeScript multi-dimensional array type declaration

I currently have an array that looks like this: handlers: string[][] For example, it contains: [["click", "inc"], ["mousedown", "dec"]] Now, I want to restructure it to look like this: [[{ handler: "click" ...

Would it be beneficial to upload and download an image using the same ajax call?

I recently made a change to my web app's image upload feature. Previously, the process involved uploading an image, retrieving the image URL, and then making a second request to download the image from the URL. Now, I have streamlined it so that when ...