You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PDF Version
First of all, thank you Tom Butler for making this awesome book, I am enjoying it so much.
I think I found some little bugs I would like to share.
On page 512 (Chapter 11 cookies and sessions. Mission accomplished? section)
public function editSubmit($id = null) {
$author = $this->authentication->getUser();
// Checking the $id VARIABLE DON'T STOP ME FROM EDITING //OTHER'S PEOPLE JOKE since id comes from the hidden input tag
// so even $id parameter addition is not necessary
if (isset($id)) {
$joke = $this->jokesTable->find('id', $id)[0] ?? null;
if ($joke['authorId'] != $author['id']) {
// This return causes some errors since the Entry point is expecting a // title and template.
return;
}
}
$joke = $_POST['joke'];
$joke['jokedate'] = new \DateTime();
$joke['authorId'] = $author['id']; $this->jokesTable->save($joke); header('location: /joke/list');
}
My suggestion would be something like the following:
public function deleteSubmit(){
if($this->checkAuthorJokeConsistency($_POST['id'])){
$this->jokesTable->delete('id', $_POST['id']);
}
header('Location: /joke/list');
}
public function editSubmit(){
$author = $this->authentication->getUser();
if($this->checkAuthorJokeConsistency( $_POST['joke']['id'])){
$joke = $_POST['joke'];
$joke['jokedate'] = new \DateTime();
$joke['authorid'] = $author['id'];
$this->jokesTable->save($joke);
}
header('Location: /joke/list');
}
// I created this function to try to avoid the copy paste.
private function checkAuthorJokeConsistency($checkVar){
$author = $this->authentication->getUser();
$joke = $this->jokesTable->find('id', $checkVar)[0] ?? null;
if($joke['authorid'] != $author['id']){
return false;
}
else{
return true;
}
}
The text was updated successfully, but these errors were encountered:
PDF Version
First of all, thank you Tom Butler for making this awesome book, I am enjoying it so much.
I think I found some little bugs I would like to share.
On page 512 (Chapter 11 cookies and sessions. Mission accomplished? section)
public function editSubmit($id = null) {
$author = $this->authentication->getUser();
// Checking the $id VARIABLE DON'T STOP ME FROM EDITING //OTHER'S PEOPLE JOKE since id comes from the hidden input tag
// so even $id parameter addition is not necessary
if (isset($id)) {
$joke = $this->jokesTable->find('id', $id)[0] ?? null;
if ($joke['authorId'] != $author['id']) {
// This return causes some errors since the Entry point is expecting a // title and template.
return;
}
}
$joke = $_POST['joke'];
$joke['jokedate'] = new \DateTime();
$joke['authorId'] = $author['id']; $this->jokesTable->save($joke); header('location: /joke/list');
}
My suggestion would be something like the following:
public function deleteSubmit(){
if($this->checkAuthorJokeConsistency($_POST['id'])){
$this->jokesTable->delete('id', $_POST['id']);
}
header('Location: /joke/list');
}
public function editSubmit(){
$author = $this->authentication->getUser();
if($this->checkAuthorJokeConsistency( $_POST['joke']['id'])){
$joke = $_POST['joke'];
$joke['jokedate'] = new \DateTime();
$joke['authorid'] = $author['id'];
$this->jokesTable->save($joke);
}
header('Location: /joke/list');
}
// I created this function to try to avoid the copy paste.
private function checkAuthorJokeConsistency($checkVar){
$author = $this->authentication->getUser();
$joke = $this->jokesTable->find('id', $checkVar)[0] ?? null;
if($joke['authorid'] != $author['id']){
return false;
}
else{
return true;
}
}
The text was updated successfully, but these errors were encountered: