Differential D9812 Diff 23561 src/applications/legalpad/controller/LegalpadDocumentSignatureVerificationController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/legalpad/controller/LegalpadDocumentSignatureVerificationController.php
<?php | <?php | ||||
final class LegalpadDocumentSignatureVerificationController | final class LegalpadDocumentSignatureVerificationController | ||||
extends LegalpadController { | extends LegalpadController { | ||||
private $code; | private $code; | ||||
public function willProcessRequest(array $data) { | public function shouldAllowPublic() { | ||||
$this->code = $data['code']; | return true; | ||||
} | } | ||||
public function shouldRequireEmailVerification() { | public function willProcessRequest(array $data) { | ||||
return false; | $this->code = $data['code']; | ||||
} | |||||
public function shouldRequireLogin() { | |||||
return false; | |||||
} | } | ||||
public function processRequest() { | public function processRequest() { | ||||
$request = $this->getRequest(); | $request = $this->getRequest(); | ||||
$user = $request->getUser(); | $viewer = $request->getUser(); | ||||
// this page can be accessed by not logged in users to valid their | |||||
// signatures. use the omnipotent user for these cases. | |||||
if (!$user->isLoggedIn()) { | |||||
$viewer = PhabricatorUser::getOmnipotentUser(); | |||||
} else { | |||||
$viewer = $user; | |||||
} | |||||
// NOTE: We're using the omnipotent user to handle logged-out signatures | |||||
// and corporate signatures. | |||||
$signature = id(new LegalpadDocumentSignatureQuery()) | $signature = id(new LegalpadDocumentSignatureQuery()) | ||||
->setViewer($viewer) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
->withSecretKeys(array($this->code)) | ->withSecretKeys(array($this->code)) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$signature) { | if (!$signature) { | ||||
$title = pht('Unable to Verify Signature'); | return $this->newDialog() | ||||
$content = pht( | ->setTitle(pht('Unable to Verify Signature')) | ||||
'The verification code you provided is incorrect or the signature '. | ->appendParagraph( | ||||
'has been removed. '. | pht( | ||||
'Make sure you followed the link in the email correctly.'); | 'The signature verification code is incorrect, or the signature '. | ||||
$uri = $this->getApplicationURI(); | 'has been invalidated. Make sure you followed the link in the '. | ||||
$continue = pht('Rats!'); | 'email correctly.')) | ||||
} else { | ->addCancelButton('/', pht('Rats!')); | ||||
$document = id(new LegalpadDocumentQuery()) | |||||
->setViewer($user) | |||||
->withPHIDs(array($signature->getDocumentPHID())) | |||||
->executeOne(); | |||||
// the document could be deleted or have its permissions changed | |||||
// 4oh4 time | |||||
if (!$document) { | |||||
return new Aphront404Response(); | |||||
} | } | ||||
$uri = '/'.$document->getMonogram(); | |||||
if ($signature->isVerified()) { | if ($signature->isVerified()) { | ||||
$title = pht('Signature Already Verified'); | return $this->newDialog() | ||||
$content = pht( | ->setTitle(pht('Signature Already Verified')) | ||||
'This signature has already been verified.'); | ->appendParagraph( | ||||
$continue = pht('Continue to Legalpad Document'); | pht( | ||||
} else { | 'This signature has already been verified.')) | ||||
$guard = AphrontWriteGuard::beginScopedUnguardedWrites(); | ->addCancelButton('/', pht('Okay')); | ||||
} | |||||
if ($request->isFormPost()) { | |||||
$signature | $signature | ||||
->setVerified(LegalpadDocumentSignature::VERIFIED) | ->setVerified(LegalpadDocumentSignature::VERIFIED) | ||||
->save(); | ->save(); | ||||
unset($guard); | |||||
$title = pht('Signature Verified'); | |||||
$content = pht('The signature is now verified.'); | |||||
$continue = pht('Continue to Legalpad Document'); | |||||
} | |||||
} | |||||
$dialog = id(new AphrontDialogView()) | |||||
->setUser($user) | |||||
->setTitle($title) | |||||
->setMethod('GET') | |||||
->addCancelButton($uri, $continue) | |||||
->appendChild($content); | |||||
$crumbs = $this->buildApplicationCrumbs(); | return $this->newDialog() | ||||
$crumbs->addTextCrumb(pht('Verify Signature')); | ->setTitle(pht('Signature Verified')) | ||||
->appendParagraph(pht('The signature is now verified.')) | |||||
->addCancelButton('/', pht('Okay')); | |||||
} | |||||
return $this->buildApplicationPage( | $document_link = phutil_tag( | ||||
'a', | |||||
array( | array( | ||||
$crumbs, | 'href' => '/'.$signature->getDocument()->getMonogram(), | ||||
$dialog, | 'target' => '_blank', | ||||
), | ), | ||||
array( | $signature->getDocument()->getTitle()); | ||||
'title' => pht('Verify Signature'), | |||||
)); | $signed_at = phabricator_datetime($signature->getDateCreated(), $viewer); | ||||
$name = $signature->getSignerName(); | |||||
$email = $signature->getSignerEmail(); | |||||
$form = id(new AphrontFormView()) | |||||
->setUser($viewer) | |||||
->appendRemarkupInstructions( | |||||
pht('Please verify this document signature.')) | |||||
->appendChild( | |||||
id(new AphrontFormMarkupControl()) | |||||
->setLabel(pht('Document')) | |||||
->setValue($document_link)) | |||||
->appendChild( | |||||
id(new AphrontFormMarkupControl()) | |||||
->setLabel(pht('Signed At')) | |||||
->setValue($signed_at)) | |||||
->appendChild( | |||||
id(new AphrontFormMarkupControl()) | |||||
->setLabel(pht('Name')) | |||||
->setValue($name)) | |||||
->appendChild( | |||||
id(new AphrontFormMarkupControl()) | |||||
->setLabel(pht('Email')) | |||||
->setValue($email)); | |||||
return $this->newDialog() | |||||
->setTitle(pht('Verify Signature?')) | |||||
->appendChild($form->buildLayoutView()) | |||||
->addCancelButton('/') | |||||
->addSubmitButton(pht('Verify Signature')); | |||||
} | } | ||||
} | } |