1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-03 14:47:30 +02:00

Add tests for checking roles for users via 'Administration' class

This commit is contained in:
Marco
2017-07-29 20:28:18 +02:00
parent bc44a08b1b
commit cd3469c137

View File

@@ -363,6 +363,24 @@ function processRequestData(\Delight\Auth\Auth $auth) {
return 'ok';
}
else if ($_POST['action'] === 'admin.hasRole') {
if (isset($_POST['id'])) {
if (isset($_POST['role'])) {
try {
return $auth->admin()->doesUserHaveRole($_POST['id'], $_POST['role']) ? 'yes' : 'no';
}
catch (\Delight\Auth\UnknownIdException $e) {
return 'unknown ID';
}
}
else {
return 'role required';
}
}
else {
return 'ID required';
}
}
else {
throw new Exception('Unexpected action: '.$_POST['action']);
}
@@ -619,6 +637,13 @@ function showGuestUserForm() {
echo '<select name="role">' . createRolesOptions() . '</select>';
echo '<button type="submit">Remove role for user by username</button>';
echo '</form>';
echo '<form action="" method="post" accept-charset="utf-8">';
echo '<input type="hidden" name="action" value="admin.hasRole" />';
echo '<input type="text" name="id" placeholder="ID" /> ';
echo '<select name="role">' . createRolesOptions() . '</select>';
echo '<button type="submit">Does user have role?</button>';
echo '</form>';
}
function createRolesOptions() {