mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add a "did verify email" event to Phabricator
Summary: Ref T7152. Gives us an event hook so we can go make users a member of any instance they've been invited to as soon as they verify an email address. Test Plan: - Used `bin/auth verify` to trigger the event. - Build out the invite flow in rSERVICES. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7152 Differential Revision: https://secure.phabricator.com/D11752
This commit is contained in:
parent
6b77dd8e37
commit
36494d4e2e
4 changed files with 95 additions and 0 deletions
|
@ -1372,6 +1372,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthManagementStripWorkflow' => 'applications/auth/management/PhabricatorAuthManagementStripWorkflow.php',
|
||||
'PhabricatorAuthManagementTrustOAuthClientWorkflow' => 'applications/auth/management/PhabricatorAuthManagementTrustOAuthClientWorkflow.php',
|
||||
'PhabricatorAuthManagementUntrustOAuthClientWorkflow' => 'applications/auth/management/PhabricatorAuthManagementUntrustOAuthClientWorkflow.php',
|
||||
'PhabricatorAuthManagementVerifyWorkflow' => 'applications/auth/management/PhabricatorAuthManagementVerifyWorkflow.php',
|
||||
'PhabricatorAuthManagementWorkflow' => 'applications/auth/management/PhabricatorAuthManagementWorkflow.php',
|
||||
'PhabricatorAuthNeedsApprovalController' => 'applications/auth/controller/PhabricatorAuthNeedsApprovalController.php',
|
||||
'PhabricatorAuthNeedsMultiFactorController' => 'applications/auth/controller/PhabricatorAuthNeedsMultiFactorController.php',
|
||||
|
@ -3768,12 +3769,14 @@ phutil_register_library_map(array(
|
|||
'DivinerLiveBook' => array(
|
||||
'DivinerDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'DivinerLivePublisher' => 'DivinerPublisher',
|
||||
'DivinerLiveSymbol' => array(
|
||||
'DivinerDAO',
|
||||
'PhabricatorPolicyInterface',
|
||||
'PhabricatorMarkupInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'DivinerMainController' => 'DivinerController',
|
||||
'DivinerPHPAtomizer' => 'DivinerAtomizer',
|
||||
|
@ -4603,6 +4606,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorAuthManagementStripWorkflow' => 'PhabricatorAuthManagementWorkflow',
|
||||
'PhabricatorAuthManagementTrustOAuthClientWorkflow' => 'PhabricatorAuthManagementWorkflow',
|
||||
'PhabricatorAuthManagementUntrustOAuthClientWorkflow' => 'PhabricatorAuthManagementWorkflow',
|
||||
'PhabricatorAuthManagementVerifyWorkflow' => 'PhabricatorAuthManagementWorkflow',
|
||||
'PhabricatorAuthManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||
'PhabricatorAuthNeedsApprovalController' => 'PhabricatorAuthController',
|
||||
'PhabricatorAuthNeedsMultiFactorController' => 'PhabricatorAuthController',
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorAuthManagementVerifyWorkflow
|
||||
extends PhabricatorAuthManagementWorkflow {
|
||||
|
||||
protected function didConstruct() {
|
||||
$this
|
||||
->setName('verify')
|
||||
->setExamples('**verify** __email__')
|
||||
->setSynopsis(
|
||||
pht(
|
||||
'Verify an unverified email address which is already attached to '.
|
||||
'an account. This will also re-execute event hooks for addresses '.
|
||||
'which are already verified.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'email',
|
||||
'wildcard' => true,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function execute(PhutilArgumentParser $args) {
|
||||
$emails = $args->getArg('email');
|
||||
if (!$emails) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('You must specify the email to verify.'));
|
||||
} else if (count($emails) > 1) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('You can only verify one address at a time.'));
|
||||
}
|
||||
$address = head($emails);
|
||||
|
||||
$email = id(new PhabricatorUserEmail())->loadOneWhere(
|
||||
'address = %s',
|
||||
$address);
|
||||
if (!$email) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht(
|
||||
'No email exists with address "%s"!',
|
||||
$address));
|
||||
}
|
||||
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($email->getUserPHID()))
|
||||
->executeOne();
|
||||
if (!$user) {
|
||||
throw new Exception(pht('Email record has invalid user PHID!'));
|
||||
}
|
||||
|
||||
$editor = id(new PhabricatorUserEditor())
|
||||
->setActor($viewer)
|
||||
->verifyEmail($user, $email);
|
||||
|
||||
$console = PhutilConsole::getConsole();
|
||||
|
||||
$console->writeOut(
|
||||
"%s\n",
|
||||
pht('Done.'));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -93,6 +93,10 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
|
|||
|
||||
$user->saveTransaction();
|
||||
|
||||
if ($email->getIsVerified()) {
|
||||
$this->didVerifyEmail($user, $email);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -574,6 +578,8 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
|
|||
|
||||
$user->endWriteLocking();
|
||||
$user->saveTransaction();
|
||||
|
||||
$this->didVerifyEmail($user, $email);
|
||||
}
|
||||
|
||||
|
||||
|
@ -674,4 +680,20 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
|
|||
));
|
||||
}
|
||||
|
||||
private function didVerifyEmail(
|
||||
PhabricatorUser $user,
|
||||
PhabricatorUserEmail $email) {
|
||||
|
||||
$event_type = PhabricatorEventType::TYPE_AUTH_DIDVERIFYEMAIL;
|
||||
$event_data = array(
|
||||
'user' => $user,
|
||||
'email' => $email,
|
||||
);
|
||||
|
||||
$event = id(new PhabricatorEvent($event_type, $event_data))
|
||||
->setUser($user);
|
||||
PhutilEventEngine::dispatchEvent($event);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ final class PhabricatorEventType extends PhutilEventType {
|
|||
const TYPE_PEOPLE_DIDRENDERMENU = 'people.didRenderMenu';
|
||||
const TYPE_AUTH_WILLREGISTERUSER = 'auth.willRegisterUser';
|
||||
const TYPE_AUTH_WILLLOGINUSER = 'auth.willLoginUser';
|
||||
const TYPE_AUTH_DIDVERIFYEMAIL = 'auth.didVerifyEmail';
|
||||
|
||||
const TYPE_SEARCH_DIDUPDATEINDEX = 'search.didUpdateIndex';
|
||||
|
||||
|
|
Loading…
Reference in a new issue