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
]
];
// 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('_serialize', ['reviews']);
// Breadcrumbs
$softwareId = $software->id;
$links = array();
$links[] = [
'name' => $software->softwarename,
......@@ -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('_serialize', ['review']);
// Breadcrumbs
$software = $review->software;
$softwareId = $software->id;
$links = array();
$links[] = [
'name' => $software->softwarename,
......
......@@ -240,6 +240,13 @@ class SoftwaresController extends AppController
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
if ($this->request->is('get') && $id != null) {
$software = $this->Softwares->get(
......@@ -706,6 +713,13 @@ class SoftwaresController extends AppController
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
$links = array();
$links[] = [
......@@ -988,6 +1002,13 @@ class SoftwaresController extends AppController
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
$links = array();
$links[] = [
......
......@@ -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
$openGraph = [
"title" => $user->username,
......@@ -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('_serialize', ['user']);
......@@ -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('_serialize', ['user']);
......@@ -931,6 +952,13 @@ class UsersController extends AppController
);
$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
$links = array();
$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