Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: replace deprecated password validator method #48

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# PrestaShop REST API Module
Easily expose REST API endpoints for your Prestashop website. No configuration needed, just install and use it.

## [Official Supported Version v4.5.1](https://addons.prestashop.com/en/website-performance/52062-rest-api-pro-version-with-fast-api-caching.html)
## [Official Supported Version v5](https://addons.prestashop.com/en/website-performance/52062-rest-api-pro-version-with-fast-api-caching.html)
New! Annotation-based API routing support added in version 5, July 2023.

## [Free Version v2.5](https://www.binshops.com/prestashop-api)
For demo and testing, not recommended for production.

## The products that use this REST API
<table>
Expand All @@ -34,20 +36,23 @@ https://rest.binshops.com/rest/bootstrap
After installation access your API endpoints at: http://yourdomain.tld/rest.

### Why we need this API module? Is not Webservice API enough?
You can get more info about this module: https://www.binshops.com/prestashop-rest-module
You can get more info about this module: https://www.binshops.com/prestashop-api

### Documentation
You can access full documentation for REST endpoints on Postman publisher:
https://documenter.getpostman.com/view/1491681/TzkyP1UC

### How to write your API?
You can easily write your API withing your existing a controller or a new one:
**domain.tld/rest/yourmodule/yourcontroller**

Read more: [Create REST API for PrestaShop modules](https://www.binshops.com/tutorial/create-rest-api-for-prestashop-modules)

### Backward Compatibility
If your shop is running on 1.7.6.x version of PrestaShop, please check the 1.7.6.x branch. The stable version supports latest Ps version.
Annotation-based API routing added in v5.
```php
/**
* @Route("/rest/get-products", name=”products”)
*/
public function getProducts()
{
// ...
}
```

### Required Modules
These native modules, which are already included in PrestaShop out of the box, are required to work with some endpoints.
Expand Down
4 changes: 4 additions & 0 deletions controllers/front/accountedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ protected function processPostRequest()
$success = false; $hasError = true;
$message = 'Password is not provided';
$messageCode = 303;
} elseif (!Validate::isAcceptablePasswordLength($password)) {
$success = false;
$message = "Invalid Password";
$messageCode = 304;
} elseif (empty($firstName)) {
$success = false; $hasError = true;
$message = "First name required";
Expand Down
16 changes: 4 additions & 12 deletions controllers/front/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,10 @@ protected function processPostRequest()
} elseif (empty($password)) {
$psdata = $this->trans('Password is not provided', [], 'Modules.Binshopsrest.Auth');
$messageCode = 303;
$hasError = true;
}

if (!version_compare(_PS_VERSION_, '8.0', '>=')) {
if (!Validate::isPasswd($password)) {
$psdata = $this->trans("Invalid Password", [], 'Modules.Binshopsrest.Auth');
$messageCode = 304;
$hasError = true;
}
}

if (!$hasError){
} elseif (!Validate::isAcceptablePasswordLength($password)) {
$psdata = $this->trans("Invalid Password", [], 'Modules.Binshopsrest.Auth');
$messageCode = 304;
} else {
Hook::exec('actionAuthenticationBefore');
$customer = new Customer();
$authentication = $customer->getByEmail(
Expand Down
4 changes: 3 additions & 1 deletion controllers/front/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ protected function processPostRequest()
} elseif (!Validate::isEmail($email)) {
$psdata = $this->trans("Invalid email address", [], 'Modules.Binshopsrest.Auth');
$messageCode = 302;
$hasError = true;
} elseif (!empty($password) && !Validate::isAcceptablePasswordLength($password)) {
$psdata = $this->trans("Invalid Password", [], 'Modules.Binshopsrest.Auth');
$messageCode = 304;
} elseif (empty($firstName)) {
$psdata = $this->trans("First name required", [], 'Modules.Binshopsrest.Auth');
$messageCode = 305;
Expand Down
2 changes: 2 additions & 0 deletions controllers/front/resetpasswordenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ protected function changePassword()
$this->psdata = $this->trans('The password and its confirmation do not match.', [], 'Shop.Notifications.Error');
}

if (!Validate::isAcceptablePasswordLength($passwd)) {
$this->psdata = $this->trans('The password is not in a valid format.', [], 'Shop.Notifications.Error');
if (version_compare(_PS_VERSION_, '8.0', '<=')) {
if (!Validate::isPasswd($passwd)) {
$this->psdata = $this->trans("Invalid Password", [], 'Modules.Binshopsrest.Auth');
Expand Down
5 changes: 4 additions & 1 deletion views/templates/admin/configure.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

<a href="https://addons.prestashop.com/en/website-performance/52062-rest-api-pro-version-with-fast-api-caching.html" target="_blank"><h2>{l s='Official Supported Version' mod='binshopsrest'}</h2></a>
<p class="font-size-100">
Get the latest supported version including the amazing features from <a href="https://addons.prestashop.com/en/website-performance/52062-rest-api-pro-version-with-fast-api-caching.html" target="_blank">Official PrestaShop Addons</a>. Let's take a look at the list of benefits.
Get the latest supported version and documentation including the amazing features from <a href="https://addons.prestashop.com/en/website-performance/52062-rest-api-pro-version-with-fast-api-caching.html" target="_blank">Official PrestaShop Addons</a>. Let's take a look at the list of benefits.
</p>
<p>
<b>New!</b> Annotation-based API routing added and structural changes made in version 5.
</p>
</div>

Expand Down