Edit tokens moved to model
This commit is contained in:
parent
be3b39bf42
commit
fd9433a2e3
3 changed files with 19 additions and 18 deletions
|
@ -8,21 +8,6 @@ class PostController
|
||||||
$callback();
|
$callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function serializePost($post)
|
|
||||||
{
|
|
||||||
$x = [];
|
|
||||||
foreach ($post->getTags() as $tag)
|
|
||||||
$x []= TextHelper::reprTag($tag->name);
|
|
||||||
foreach ($post->getRelations() as $relatedPost)
|
|
||||||
$x []= TextHelper::reprPost($relatedPost);
|
|
||||||
$x []= $post->safety;
|
|
||||||
$x []= $post->source;
|
|
||||||
$x []= $post->fileHash;
|
|
||||||
natcasesort($x);
|
|
||||||
$x = join(' ', $x);
|
|
||||||
return md5($x);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function handleUploadErrors($file)
|
private static function handleUploadErrors($file)
|
||||||
{
|
{
|
||||||
switch ($file['error'])
|
switch ($file['error'])
|
||||||
|
@ -261,7 +246,7 @@ class PostController
|
||||||
if (InputHelper::get('submit'))
|
if (InputHelper::get('submit'))
|
||||||
{
|
{
|
||||||
$editToken = InputHelper::get('edit-token');
|
$editToken = InputHelper::get('edit-token');
|
||||||
if ($editToken != self::serializePost($post))
|
if ($editToken != $post->getEditToken())
|
||||||
throw new SimpleException('This post was already edited by someone else in the meantime');
|
throw new SimpleException('This post was already edited by someone else in the meantime');
|
||||||
|
|
||||||
LogHelper::bufferChanges();
|
LogHelper::bufferChanges();
|
||||||
|
@ -485,7 +470,6 @@ class PostController
|
||||||
$this->context->transport->post = $post;
|
$this->context->transport->post = $post;
|
||||||
$this->context->transport->prevPostId = $prevPost ? $prevPost->id : null;
|
$this->context->transport->prevPostId = $prevPost ? $prevPost->id : null;
|
||||||
$this->context->transport->nextPostId = $nextPost ? $nextPost->id : null;
|
$this->context->transport->nextPostId = $nextPost ? $nextPost->id : null;
|
||||||
$this->context->transport->editToken = self::serializePost($post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -422,4 +422,21 @@ class PostEntity extends AbstractEntity
|
||||||
unlink($srcPath);
|
unlink($srcPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getEditToken()
|
||||||
|
{
|
||||||
|
$x = [];
|
||||||
|
foreach ($this->getTags() as $tag)
|
||||||
|
$x []= TextHelper::reprTag($tag->name);
|
||||||
|
foreach ($this->getRelations() as $relatedPost)
|
||||||
|
$x []= TextHelper::reprPost($relatedPost);
|
||||||
|
$x []= $this->safety;
|
||||||
|
$x []= $this->source;
|
||||||
|
$x []= $this->fileHash;
|
||||||
|
natcasesort($x);
|
||||||
|
$x = join(' ', $x);
|
||||||
|
return md5($x);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<label class="left" for="tags">Tags:</label>
|
<label class="left" for="tags">Tags:</label>
|
||||||
<div class="input-wrapper"><input type="text" name="tags" id="tags" placeholder="enter some tags…" value="<?php echo join(',', array_map(function($tag) { return $tag->name; }, $this->context->transport->post->getTags())) ?>"/></div>
|
<div class="input-wrapper"><input type="text" name="tags" id="tags" placeholder="enter some tags…" value="<?php echo join(',', array_map(function($tag) { return $tag->name; }, $this->context->transport->post->getTags())) ?>"/></div>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="edit-token" id="edit-token" value="<?php echo $this->context->transport->editToken ?>"/>
|
<input type="hidden" name="edit-token" id="edit-token" value="<?php echo $this->context->transport->post->getEditToken() ?>"/>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<?php if (PrivilegesHelper::confirm(Privilege::EditPostSource, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
|
<?php if (PrivilegesHelper::confirm(Privilege::EditPostSource, PrivilegesHelper::getIdentitySubPrivilege($this->context->transport->post->getUploader()))): ?>
|
||||||
|
|
Loading…
Reference in a new issue