Inproved handling of missing user IDs

This commit is contained in:
Erik Thuning 2019-04-11 11:02:52 +02:00
parent 3074136cf7
commit f26e281b9c
2 changed files with 17 additions and 7 deletions

@ -664,22 +664,24 @@ class User {
}
public function __construct($clue, $type = 'id') {
$id = $clue;
$find = null;
switch($type) {
case 'id':
$find = prepare('select `id` from `user` where `id`=?');
bind($find, 'i', $clue);
break;
case 'name':
$find = prepare('select `id` from `user` where `name`=?');
bind($find, 's', $clue);
execute($find);
$id = result_single($find)['id'];
if($id === null) {
throw new Exception("Invalid username '$clue'");
}
break;
default:
throw new Exception('Invalid type');
}
execute($find);
$id = result_single($find)['id'];
if($id === null) {
throw new Exception("Invalid username '$clue'");
}
$this->id = $id;
$this->update_fields();
}

@ -586,7 +586,15 @@ class UserPage extends Page {
$this->action = $_GET['action'];
}
if(isset($_GET['id'])) {
$this->user = new User($_GET['id']);
$id = $_GET['id'];
if($id) {
try {
$this->user = new User($_GET['id']);
} catch(Exception $e) {
$this->user = null;
$this->action = 'list';
}
}
}
switch($this->action) {
case 'show':