- added trait for checking authorisation with redirect stored in session to return - shows which controllers requires auth, adds check function
73 lines
1.6 KiB
PHP
73 lines
1.6 KiB
PHP
<?php
|
|
|
|
class UserController implements CRUD {
|
|
|
|
use RequiresAuth;
|
|
|
|
// list all users (admin only)
|
|
|
|
public function index($f3){
|
|
|
|
$this->check_access($f3);
|
|
|
|
$db = $f3->get('DB');
|
|
$users = $db->exec(
|
|
'SELECT u.*, r.role AS role_name
|
|
FROM users u
|
|
LEFT JOIN roles r ON r.id = u.role
|
|
ORDER BY id ASC'
|
|
);
|
|
$f3->set('users', $users);
|
|
|
|
$f3->set('content', '../ui/views/user/index.html');
|
|
echo \Template::instance()->render('../ui/templates/layout.html');
|
|
}
|
|
|
|
public function editForm($f3){
|
|
$this->check_access($f3);
|
|
|
|
$user_id = (int) $f3->get('PARAMS.id');
|
|
$db = $f3->get('DB');
|
|
|
|
$rows = $db->exec(
|
|
'SELECt * FROM users WHERE id = ? LIMIT 1',
|
|
[$user_id]
|
|
);
|
|
if(!$rows){
|
|
$f3->reroute('/users');
|
|
}
|
|
$f3->set('edit_user', $rows[0]);
|
|
$f3->set('content', '../ui/views/user/edit.html');
|
|
echo \Template::instance()->render('../ui/templates/layout.html');
|
|
}
|
|
|
|
public function update($f3){
|
|
|
|
$this->check_access($f3);
|
|
|
|
$user_id = (int) $f3->get('PARAMS.id');
|
|
$new_username = $f3->get('POST.username');
|
|
// $new_role = $f3->get('POST.role_name')
|
|
$db = $f3->get('DB');
|
|
$db->exec(
|
|
'UPDATE users SET username = ? WHERE id =? LIMIT 1',
|
|
[$new_username, $user_id]);
|
|
$f3->reroute('/users');
|
|
}
|
|
|
|
public function createForm($f3)
|
|
{
|
|
|
|
}
|
|
|
|
public function create($f3)
|
|
{
|
|
|
|
}
|
|
|
|
public function view($f3)
|
|
{
|
|
|
|
}
|
|
|
|
} |