Skip to content

Commit

Permalink
chore: check if user exists
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Feb 3, 2025
1 parent 50d763f commit 912af7e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/SignFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function sign(string $method, array $elements = [], string $identifyValue
$libreSignFile = $this->signFileService->getLibresignFile($fileId, $signRequestUuid);
$signRequest = $this->signFileService->getSignRequestToSign($libreSignFile, $signRequestUuid, $user);
$this->validateHelper->validateVisibleElementsRelation($elements, $signRequest, $user);
$this->validateHelper->validateCredentials($signRequest, $user, $method, $identifyValue, $token);
$this->validateHelper->validateCredentials($signRequest, $method, $identifyValue, $token);
if ($method === 'password') {
$this->signFileService->setPassword($token);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/ValidateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public function canSignWithIdentificationDocumentStatus(?IUser $user, int $statu
}
}

public function validateCredentials(SignRequest $signRequest, ?IUser $user, string $identifyMethodName, string $identifyValue, string $token): void {
public function validateCredentials(SignRequest $signRequest, string $identifyMethodName, string $identifyValue, string $token): void {
$this->validateIfIdentifyMethodExists($identifyMethodName);
if ($signRequest->getId()) {
$multidimensionalList = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId());
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/SignFileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ public function setVisibleElements(array $list): self {
} else {
throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1);
}
} elseif (!$this->user instanceof IUser) {
throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1);
} else {
$userElement = $this->userElementMapper->findOne([
'user_id' => $this->user->getUID(),
Expand Down Expand Up @@ -467,6 +469,7 @@ public function getSignRequestToSign(FileEntity $libresignFile, ?string $signReq
$identifyMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($signRequest->getId());
$found = array_filter($identifyMethods, function (IdentifyMethod $identifyMethod) use ($user) {
if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL
&& $user
&& (
$identifyMethod->getIdentifierValue() === $user->getUID()
|| $identifyMethod->getIdentifierValue() === $user->getEMailAddress()
Expand All @@ -475,6 +478,7 @@ public function getSignRequestToSign(FileEntity $libresignFile, ?string $signReq
return true;
}
if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_ACCOUNT
&& $user
&& $identifyMethod->getIdentifierValue() === $user->getUID()
) {
return true;
Expand Down

0 comments on commit 912af7e

Please sign in to comment.