1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-05 15:47:25 +02:00

Allow for roles to be taken away from users via 'Administration' class

This commit is contained in:
Marco
2017-07-29 19:06:13 +02:00
parent b7e6ca6dee
commit 1a4041ea60

View File

@@ -186,6 +186,79 @@ final class Administration extends UserManager {
);
}
/**
* Takes away the specified role from the user with the given ID
*
* A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles)
*
* @param int $userId the ID of the user to take the role away from
* @param int $role the role as one of the constants from the {@see Role} class
* @throws UnknownIdException if no user with the specified ID has been found
*
* @see Role
*/
public function removeRoleForUserById($userId, $role) {
$userFound = $this->removeRoleForUserByColumnValue(
'id',
(int) $userId,
$role
);
if ($userFound === false) {
throw new UnknownIdException();
}
}
/**
* Takes away the specified role from the user with the given email address
*
* A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles)
*
* @param string $userEmail the email address of the user to take the role away from
* @param int $role the role as one of the constants from the {@see Role} class
* @throws InvalidEmailException if no user with the specified email address has been found
*
* @see Role
*/
public function removeRoleForUserByEmail($userEmail, $role) {
$userEmail = self::validateEmailAddress($userEmail);
$userFound = $this->removeRoleForUserByColumnValue(
'email',
$userEmail,
$role
);
if ($userFound === false) {
throw new InvalidEmailException();
}
}
/**
* Takes away the specified role from the user with the given username
*
* A user may have any number of roles (i.e. no role at all, a single role, or any combination of roles)
*
* @param string $username the username of the user to take the role away from
* @param int $role the role as one of the constants from the {@see Role} class
* @throws UnknownUsernameException if no user with the specified username has been found
* @throws AmbiguousUsernameException if multiple users with the specified username have been found
*
* @see Role
*/
public function removeRoleForUserByUsername($username, $role) {
$userData = $this->getUserDataByUsername(
\trim($username),
[ 'id' ]
);
$this->removeRoleForUserByColumnValue(
'id',
(int) $userData['id'],
$role
);
}
protected function throttle($actionType, $customSelector = null) {
// do nothing
}