Only administrator can make changes to categories

This commit is contained in:
Gregorio Chiko Putra 2017-09-11 10:20:20 +07:00
parent eeaa2427a0
commit 146b5d33e6
2 changed files with 14 additions and 7 deletions

View File

@ -81,11 +81,11 @@ class Posts
$url = 'Data/pengumuman.html'; $url = 'Data/pengumuman.html';
$status = ''; $privilage = '';
if (Session::exists('userid')) { if (Session::exists('userid')) {
$post = $this->model->showAll(); $post = $this->model->showAll();
$status = 'admin'; $privilage = Session::get('privilage');
} }
if ($post !== false) { if ($post !== false) {
@ -102,7 +102,7 @@ class Posts
} }
View::render($url, [ View::render($url, [
'posts' => $posts, 'posts' => $posts,
'status' => $status 'privilage' => $privilage
]); ]);
} }
@ -198,6 +198,11 @@ class Posts
public function category() public function category()
{ {
if (Session::exists('userid')) { if (Session::exists('userid')) {
if (Session::get('privilage') != 1) {
Session::flash('info', 'Hanya admin yang bisa mengatur kategori.');
Redirect::to('/');
die();
}
$categories = []; $categories = [];
$get_categories = $this->model->showAll([], 'kategori'); $get_categories = $this->model->showAll([], 'kategori');
@ -212,7 +217,7 @@ class Posts
'token' => Token::generate() 'token' => Token::generate()
]); ]);
} else { } else {
throw new \Exception("Bad request", 400); throw new \Exception("Page not found", 404);
} }
} }

View File

@ -29,9 +29,11 @@
<br /> <br />
{% if status %} {% if privilage != "" %}
<a href="/posts/entry">+ Tambah Pengumuman</a> <a href="/posts/entry">+ Tambah Pengumuman</a>
<a href="/posts/category">+ Tambah Kategori</a> {% if privilage == 1 %}
<a href="/posts/category">+ Tambah Kategori</a>
{% endif %}
<a href="/logout">Keluar</a> <a href="/logout">Keluar</a>
{% endif %} {% endif %}
{% endblock %} {% endblock %}