Skip to content

Commit

Permalink
Fix way to get email when is using account as identify method
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Mar 22, 2024
1 parent 1b65610 commit 63ca0cf
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/Service/IdentifyMethod/SignatureMethod/EmailToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace OCA\Libresign\Service\IdentifyMethod\SignatureMethod;

use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Helper\JSActions;
use OCA\Libresign\Service\IdentifyMethod\IdentifyMethodService;
use Wobeto\EmailBlur\Blur;

Expand All @@ -40,19 +42,32 @@ public function __construct(
}

public function toArray(): array {
$return = parent::toArray();
$entity = $this->getEntity();

if ($entity->getIdentifierKey() === 'email') {
$email = $entity->getIdentifierValue();
} elseif ($entity->getIdentifierKey() === 'account') {
$signer = $this->identifyMethodService->getUserManager()->get($entity->getIdentifierValue());
$email = $signer->getEMailAddress();
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new LibresignException(json_encode([
'action' => JSActions::ACTION_DO_NOTHING,
'errors' => [$this->identifyMethodService->getL10n()->t('Invalid email')],
]));
}
$return = parent::toArray();
$return['identifyMethod'] = $entity->getIdentifierKey();
$return['needCode'] = empty($entity->getCode())
|| empty($entity->getIdentifiedAtDate())
|| empty($this->codeSentByUser);
$return['hasConfirmCode'] = !empty($entity->getCode());
$return['blurredEmail'] = $this->getBlurredEmail();
$return['hashOfEmail'] = md5($this->getEntity()->getIdentifierValue());
$return['blurredEmail'] = $this->blurEmail($email);
$return['hashOfEmail'] = md5($email);
return $return;
}

private function getBlurredEmail(): string {
$email = $this->getEntity()->getIdentifierValue();
private function blurEmail(string $email): string {
$blur = new Blur($email);
return $blur->make();
}
Expand Down

0 comments on commit 63ca0cf

Please sign in to comment.