Skip to content

Commit

Permalink
Merge pull request #2580 from LibreSign/bugfix/use-email-token-with-a…
Browse files Browse the repository at this point in the history
…ccount

Bugfix: use email token with account
  • Loading branch information
vitormattos authored Mar 22, 2024
2 parents 39f1838 + 63ca0cf commit 898ac8f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/Service/IdentifyMethod/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function validateToIdentify(): void {
$signer = $this->getSigner();
$this->throwIfNotAuthenticated();
$this->authenticatedUserIsTheSigner($signer);
$this->throwIfInvalidToken();
$this->throwIfMaximumValidityExpired();
$this->throwIfRenewalIntervalExpired();
$this->throwIfAlreadySigned();
Expand Down
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
4 changes: 2 additions & 2 deletions src/views/SignPDF/_partials/ModalEmailManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default {
generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', { fileId: this.fileId }),
{
identify: this.sendTo,
identifyMethod: 'email',
identifyMethod: this.signMethodsStore.settings.emailToken.identifyMethod,
signMethod: 'emailToken',
},
)
Expand All @@ -177,7 +177,7 @@ export default {
generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{uuid}/code', { uuid: this.uuid }),
{
identify: this.sendTo,
identifyMethod: 'email',
identifyMethod: this.signMethodsStore.settings.emailToken.identifyMethod,
signMethod: 'emailToken',
},
)
Expand Down
2 changes: 1 addition & 1 deletion src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export default {
},
async signWithEmailToken() {
return this.signDocument({
method: 'email',
method: this.signMethodsStore.settings.emailToken.identifyMethod,
token: this.signMethodsStore.settings.emailToken.token,
})
},
Expand Down

0 comments on commit 898ac8f

Please sign in to comment.