Adding token and current timestamp to html.

This commit is contained in:
Gregorio Chiko Putra 2017-09-05 08:54:32 +07:00
parent 06c4e2a74e
commit 45dbe24da7
3 changed files with 17 additions and 6 deletions

View File

@ -3,6 +3,7 @@ namespace App\Controllers;
use \Core\View;
use App\Models\Post;
use \Core\Token;
class Posts
{
@ -26,9 +27,13 @@ class Posts
public function entry()
{
$categories = $this->model->showCategories();
$date = new \DateTime();
$timestamp = $date->format('Y/m/d H:i:s');
// echo "You can entry new data here."; // Nanti di replace sama twig view ke App\Views\Data\entry_pengumuman.html
View::render('Data/entry_pengumuman.html', [
'categories' => $categories
'categories' => $categories,
'timestamp' => $timestamp,
'token' => Token::generate()
]);
return true;
}
@ -37,6 +42,8 @@ class Posts
{
if ($id) {
$posts = $this->model->showSingle($id);
$date = new \DateTime();
$timestamp = $date->format('Y/m/d H:i:s');
// echo "You can edit exists data with id $id here"; // Nanti di replace sama twig view ke App\Views\Data\edit_pengumuman.html
View::render(
'Data/edit_pengumuman.html',
@ -46,7 +53,9 @@ class Posts
'created_at' => $posts['created_at'],
'creator' => $posts['creator'],
'edited_at' => $posts['edited_at'],
'editor' => $posts['editor']
'editor' => $posts['editor'],
'timestamp' => $timestamp,
'token' => Token::generate()
]
);
return true;

View File

@ -40,13 +40,13 @@
<input type="text" name="editor" value="User {{ editor }}" disabled>
<!-- Current Timestamp -->
<input type="hidden" name="_currts" value="##CURRENT_TIMESTAMP##">
<input type="hidden" name="_currts" value={{ timestamp }}>
<!-- Method -->
<input type="hidden" name="_method" value="put">
<!-- Token -->
<input type="hidden" name="_token" value="##TOKEN##">
<input type="hidden" name="_token" value={{ token }}>
<br>

View File

@ -19,13 +19,15 @@
<textarea name="konten" rows="3" cols="30"></textarea>
<!-- Current Timestamp -->
<input type="hidden" name="_currts" value="##CURRENT_TIMESTAMP##">
<input type="hidden" name="_currts" value={{ timestamp }}>
<!-- Method -->
<input type="hidden" name="_method" value="post">
<!-- Token -->
<input type="hidden" name="_token" value="##TOKEN##">
<input type="hidden" name="_token" value={{ token }}>
<br>
<button type="submit" name="entry">Entry</button>
</form>