Commit ba88fe7a authored by Taddeus Kroes's avatar Taddeus Kroes

Added users overview page for admins

parent 6544335c
...@@ -200,3 +200,21 @@ msgstr "Toon/verberg kleuren" ...@@ -200,3 +200,21 @@ msgstr "Toon/verberg kleuren"
msgid "User not found" msgid "User not found"
msgstr "Gebruiker niet gevonden" msgstr "Gebruiker niet gevonden"
msgid "Insufficient permissions"
msgstr "Onvoldoende gemachtigd"
msgid "Users"
msgstr "Gebruikers"
msgid "Id"
msgstr "Id"
msgid "Role"
msgstr "Rol"
msgid "admin"
msgstr "administrator"
msgid "member"
msgstr "gebruiker"
...@@ -166,3 +166,9 @@ $app->get('/user/:id/plot', function ($id) use ($app, $db, $user) { ...@@ -166,3 +166,9 @@ $app->get('/user/:id/plot', function ($id) use ($app, $db, $user) {
$app->render('user/plot', compact('dbuser', 'form', 'matches')); $app->render('user/plot', compact('dbuser', 'form', 'matches'));
}); });
$app->get('/user', function () use ($app, $db) {
require_admin_access();
$users = $db->table('user')->order('id');
$app->render('user/list', compact('users'));
});
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
['matches', _('Matches')], ['matches', _('Matches')],
["user/{$user->getId()}", _('Profile')], ["user/{$user->getId()}", _('Profile')],
["user/{$user->getId()}/plot", _('Progress graph')], ["user/{$user->getId()}/plot", _('Progress graph')],
$user->isInRole('admin') ? ['user', _('Users')],
['logout', _('Logout')], ['logout', _('Logout')],
] : [ ] : [
['login', _('Login')], ['login', _('Login')],
......
{extends '../layout.latte'}
{block content}
<h2 class="page-header">{_'Users'}</h2>
<table id="results" class="table table-hover matches">
<thead>
<tr>
<th>{_'Id'}</th>
<th>{_'Username'}</th>
<th>{_'Role'}</th>
</tr>
</thead>
<tbody>
<tr n:foreach="$users as $user" data-href="user/{$user->id}">
<td>{$user->id}</td>
<td>{$user->username}</td>
<td>{_$user->role}</td>
</tr>
</tbody>
</table>
{/block}
...@@ -51,8 +51,18 @@ function require_user_access($user_id) { ...@@ -51,8 +51,18 @@ function require_user_access($user_id) {
if (!$user->isLoggedIn()) if (!$user->isLoggedIn())
$app->redirect(ROOT_URL . '/login'); $app->redirect(ROOT_URL . '/login');
if ($user->getId() != $user_id && !in_array('admin', $user->getRoles())) if ($user->getId() != $user_id && !$user->isInRole('admin'))
$app->halt(403, _('No access to this user')); $app->halt(403, _('Insufficient permissions'));
}
function require_admin_access() {
global $user, $app;
if (!$user->isLoggedIn())
$app->redirect(ROOT_URL . '/login');
if (!$user->isInRole('admin'))
$app->halt(403, _('Insufficient permissions'));
} }
function find_match($id) { function find_match($id) {
...@@ -99,8 +109,6 @@ class UserHelper { ...@@ -99,8 +109,6 @@ class UserHelper {
private $user; private $user;
public function __construct(IRow $dbuser) { public function __construct(IRow $dbuser) {
global $db;
$this->db = $db;
$this->user = $dbuser; $this->user = $dbuser;
} }
......
Markdown is supported
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