1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-04 15:17:28 +02:00

Allow for roles to be checked for users via 'Administration' class

This commit is contained in:
Marco
2017-07-29 20:24:24 +02:00
parent 8ff4242f8f
commit bc44a08b1b

View File

@@ -259,6 +259,32 @@ final class Administration extends UserManager {
); );
} }
/**
* Returns whether the user with the given ID has the specified role
*
* @param int $userId the ID of the user to check the roles for
* @param int $role the role as one of the constants from the {@see Role} class
* @return bool
* @throws UnknownIdException if no user with the specified ID has been found
*
* @see Role
*/
public function doesUserHaveRole($userId, $role) {
$userId = (int) $userId;
$role = (int) $role;
$rolesBitmask = $this->db->selectValue(
'SELECT roles_mask FROM users WHERE id = ?',
[ $userId ]
);
if ($rolesBitmask === null) {
throw new UnknownIdException();
}
return ($rolesBitmask & $role) === $role;
}
protected function throttle($actionType, $customSelector = null) { protected function throttle($actionType, $customSelector = null) {
// do nothing // do nothing
} }