mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-02 14:17:26 +02:00
Add tests for method 'deleteUserById' and related methods
This commit is contained in:
@@ -234,6 +234,40 @@ function processRequestData(\Delight\Auth\Auth $auth) {
|
|||||||
return 'username already exists';
|
return 'username already exists';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ($_POST['action'] === 'admin.deleteUser') {
|
||||||
|
if (isset($_POST['id'])) {
|
||||||
|
try {
|
||||||
|
$auth->admin()->deleteUserById($_POST['id']);
|
||||||
|
}
|
||||||
|
catch (\Delight\Auth\UnknownIdException $e) {
|
||||||
|
return 'unknown ID';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (isset($_POST['email'])) {
|
||||||
|
try {
|
||||||
|
$auth->admin()->deleteUserByEmail($_POST['email']);
|
||||||
|
}
|
||||||
|
catch (\Delight\Auth\InvalidEmailException $e) {
|
||||||
|
return 'unknown email address';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif (isset($_POST['username'])) {
|
||||||
|
try {
|
||||||
|
$auth->admin()->deleteUserByUsername($_POST['username']);
|
||||||
|
}
|
||||||
|
catch (\Delight\Auth\UnknownUsernameException $e) {
|
||||||
|
return 'unknown username';
|
||||||
|
}
|
||||||
|
catch (\Delight\Auth\AmbiguousUsernameException $e) {
|
||||||
|
return 'ambiguous username';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 'either ID, email or username required';
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'ok';
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new Exception('Unexpected action: '.$_POST['action']);
|
throw new Exception('Unexpected action: '.$_POST['action']);
|
||||||
}
|
}
|
||||||
@@ -381,4 +415,22 @@ function showGuestUserForm() {
|
|||||||
echo '</select> ';
|
echo '</select> ';
|
||||||
echo '<button type="submit">Create user</button>';
|
echo '<button type="submit">Create user</button>';
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
|
|
||||||
|
echo '<form action="" method="post" accept-charset="utf-8">';
|
||||||
|
echo '<input type="hidden" name="action" value="admin.deleteUser" />';
|
||||||
|
echo '<input type="text" name="id" placeholder="ID" /> ';
|
||||||
|
echo '<button type="submit">Delete user by ID</button>';
|
||||||
|
echo '</form>';
|
||||||
|
|
||||||
|
echo '<form action="" method="post" accept-charset="utf-8">';
|
||||||
|
echo '<input type="hidden" name="action" value="admin.deleteUser" />';
|
||||||
|
echo '<input type="text" name="email" placeholder="Email" /> ';
|
||||||
|
echo '<button type="submit">Delete user by email</button>';
|
||||||
|
echo '</form>';
|
||||||
|
|
||||||
|
echo '<form action="" method="post" accept-charset="utf-8">';
|
||||||
|
echo '<input type="hidden" name="action" value="admin.deleteUser" />';
|
||||||
|
echo '<input type="text" name="username" placeholder="Username" /> ';
|
||||||
|
echo '<button type="submit">Delete user by username</button>';
|
||||||
|
echo '</form>';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user