Inproved handling of missing user IDs
This commit is contained in:
parent
3074136cf7
commit
f26e281b9c
@ -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':
|
||||
|
Loading…
x
Reference in New Issue
Block a user