Commit 256369d3 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FIX: check that the current URL is correct (2)

Software:
- /softwares/<id> --> redirect to /<lang>/softwares/<id>
- /softwares/<id>/reviews           --> redirect to /<lang>/...
- /softwares/<id>/reviews/<idR>     --> redirect to /<lang>/...
- /softwares/usersSoftware/<id>     --> redirect to /<lang>/...
- /softwares/servicesProviders/<id> --> redirect to /<lang>/...

User:
- /users/<id> --> redirect to /<lang>/users/<id>
- /users/<id>/reviews            ---> redirect to /<lang>/...
- /users/usedSoftwares/id        ---> redirect to /<lang>/...
- /users/providerforSoftwares/id ---> redirect to /<lang>/...

Refs:
parent fa87044e
...@@ -85,12 +85,19 @@ class ReviewsController extends AppController ...@@ -85,12 +85,19 @@ class ReviewsController extends AppController
] ]
]; ];
// Check that the current URL is correct
$softwareId = $software->id;
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/softwares/$softwareId/reviews";
if ($allowedUrl !== $this->request->here(false)) {
return $this->redirect("$allowedUrl", 301);
}
$this->set('reviews', $this->paginate($this->Reviews)); $this->set('reviews', $this->paginate($this->Reviews));
$this->set('_serialize', ['reviews']); $this->set('_serialize', ['reviews']);
// Breadcrumbs // Breadcrumbs
$softwareId = $software->id;
$links = array(); $links = array();
$links[] = [ $links[] = [
'name' => $software->softwarename, 'name' => $software->softwarename,
...@@ -142,12 +149,20 @@ class ReviewsController extends AppController ...@@ -142,12 +149,20 @@ class ReviewsController extends AppController
] ]
] ]
); );
$software = $review->software;
$softwareId = $software->id;
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/softwares/$softwareId/reviews/". (int) $id;
if ($allowedUrl !== $this->request->here(false)) {
return $this->redirect("$allowedUrl", 301);
}
$this->set('review', $review); $this->set('review', $review);
$this->set('_serialize', ['review']); $this->set('_serialize', ['review']);
// Breadcrumbs // Breadcrumbs
$software = $review->software;
$softwareId = $software->id;
$links = array(); $links = array();
$links[] = [ $links[] = [
'name' => $software->softwarename, 'name' => $software->softwarename,
......
...@@ -240,6 +240,13 @@ class SoftwaresController extends AppController ...@@ -240,6 +240,13 @@ class SoftwaresController extends AppController
public function view($id = null) public function view($id = null)
{ {
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/softwares/". (int) $id;
if ($allowedUrl !== $this->request->here(false) && !$this->request->is('json')) {
return $this->redirect("$allowedUrl", 301);
}
// an id is specified => get details of the software // an id is specified => get details of the software
if ($this->request->is('get') && $id != null) { if ($this->request->is('get') && $id != null) {
$software = $this->Softwares->get( $software = $this->Softwares->get(
...@@ -706,6 +713,13 @@ class SoftwaresController extends AppController ...@@ -706,6 +713,13 @@ class SoftwaresController extends AppController
throw new SoftwareNotFoundException("The software with the id " . $id . " does not exist"); throw new SoftwareNotFoundException("The software with the id " . $id . " does not exist");
} }
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/softwares/usersSoftware/". (int) $id;
if ($allowedUrl !== $this->request->here(false) && $this->request->is('get')) {
return $this->redirect("$allowedUrl", 301);
}
// Breadcrumbs // Breadcrumbs
$links = array(); $links = array();
$links[] = [ $links[] = [
...@@ -988,6 +1002,13 @@ class SoftwaresController extends AppController ...@@ -988,6 +1002,13 @@ class SoftwaresController extends AppController
throw new SoftwareNotFoundException("The software with the id " . $id . " does not exist"); throw new SoftwareNotFoundException("The software with the id " . $id . " does not exist");
} }
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/softwares/servicesProviders/". (int) $id;
if ($allowedUrl !== $this->request->here(false) && $this->request->is('get')) {
return $this->redirect("$allowedUrl", 301);
}
// Breadcrumbs // Breadcrumbs
$links = array(); $links = array();
$links[] = [ $links[] = [
......
...@@ -361,6 +361,13 @@ class UsersController extends AppController ...@@ -361,6 +361,13 @@ class UsersController extends AppController
] ]
); );
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/users/". (int) $id;
if ($allowedUrl !== $this->request->here(false) && !$this->request->is('json')) {
return $this->redirect("$allowedUrl", 301);
}
//For Social MEDIAS => OPENGRAPH //For Social MEDIAS => OPENGRAPH
$openGraph = [ $openGraph = [
"title" => $user->username, "title" => $user->username,
...@@ -826,6 +833,13 @@ class UsersController extends AppController ...@@ -826,6 +833,13 @@ class UsersController extends AppController
] ]
); );
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/users/usedSoftwares/". (int) $id;
if ($allowedUrl !== $this->request->here(false)) {
return $this->redirect("$allowedUrl", 301);
}
$this->set(compact('user')); $this->set(compact('user'));
$this->set('_serialize', ['user']); $this->set('_serialize', ['user']);
...@@ -880,6 +894,13 @@ class UsersController extends AppController ...@@ -880,6 +894,13 @@ class UsersController extends AppController
] ]
); );
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/users/providerforSoftwares/". (int) $id;
if ($allowedUrl !== $this->request->here(false)) {
return $this->redirect("$allowedUrl", 301);
}
$this->set(compact('user')); $this->set(compact('user'));
$this->set('_serialize', ['user']); $this->set('_serialize', ['user']);
...@@ -931,6 +952,13 @@ class UsersController extends AppController ...@@ -931,6 +952,13 @@ class UsersController extends AppController
); );
$id = $user->id; $id = $user->id;
// Check that the current URL is correct
$lang = $this->selectedLanguage;
$allowedUrl = "/$lang/users/$id/reviews";
if ($allowedUrl !== $this->request->here(false)) {
return $this->redirect("$allowedUrl", 301);
}
// Breadcrumbs // Breadcrumbs
$links = array(); $links = array();
$links[] = [ $links[] = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment