Skip to content
Snippets Groups Projects

feat: :guitar: RPC method - find user by email

+ 35
0
@@ -119,6 +119,41 @@ class AdapterRpc extends Adapter
return $this->getPerunUser($idpEntityId, $uids);
}
public function getPerunUserByEmail($emailAttrUrn, $emailValue)
{
$user = null;
$users = $this->connector->get('usersManager', 'getUsersByAttributeValue', [
'attributeName' => $emailAttrUrn,
'attributeValue' => $emailValue,
]);
if (count($users) > 1) {
throw new Exception('Multiple users with email ' . $emailValue . ' found');
} elseif (count($users) === 0) {
throw new Exception('No users with email ' . $emailValue . ' found');
} else {
$user = $users[0];
$name = '';
if (!empty($user['titleBefore'])) {
$name .= $user['titleBefore'] . ' ';
}
if (!empty($user['firstName'])) {
$name .= $user['firstName'] . ' ';
}
if (!empty($user['middleName'])) {
$name .= $user['middleName'] . ' ';
}
if (!empty($user['lastName'])) {
$name .= $user['lastName'];
}
if (!empty($user['titleAfter'])) {
$name .= ' ' . $user['titleAfter'];
}
return new User($user['id'], $name);
}
}
public function getMemberGroups($user, $vo)
{
try {
Loading