@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move email verification into PhabricatorUserEditor

Summary: Both email verify and welcome links now verify email, centralize them and record them in the user activity log.

Test Plan:
- Followed a "verify email" link and got verified.
- Followed a "welcome" (verifying) link.
- Followed a "reset" (non-verifying) link.
- Looked in the activity log for the verifications.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D9284

+67 -25
+3 -12
src/applications/auth/controller/PhabricatorAuthOneTimeLoginController.php
··· 102 102 $token->delete(); 103 103 104 104 if ($target_email) { 105 - $target_user->openTransaction(); 106 - $target_email->setIsVerified(1); 107 - $target_email->save(); 108 - 109 - // If this was the user's primary email address, also mark their 110 - // account as verified. 111 - $primary_email = $target_user->loadPrimaryEmail(); 112 - if ($primary_email->getID() == $target_email->getID()) { 113 - $target_user->setIsEmailVerified(1); 114 - $target_user->save(); 115 - } 116 - $target_user->saveTransaction(); 105 + id(new PhabricatorUserEditor()) 106 + ->setActor($target_user) 107 + ->verifyEmail($target_user, $target_email); 117 108 } 118 109 unset($unguarded); 119 110
+3 -13
src/applications/auth/controller/PhabricatorEmailVerificationController.php
··· 52 52 'This email address has already been verified.'); 53 53 $continue = pht('Continue to Phabricator'); 54 54 } else if ($request->isFormPost()) { 55 - $email->openTransaction(); 56 55 57 - $email->setIsVerified(1); 58 - $email->save(); 59 - 60 - // If the user just verified their primary email address, mark their 61 - // account as email verified. 62 - $user_primary = $user->loadPrimaryEmail(); 63 - if ($user_primary->getID() == $email->getID()) { 64 - $user->setIsEmailVerified(1); 65 - $user->save(); 66 - } 67 - 68 - $email->saveTransaction(); 56 + id(new PhabricatorUserEditor()) 57 + ->setActor($user) 58 + ->verifyEmail($user, $email); 69 59 70 60 $title = pht('Address Verified'); 71 61 $content = pht(
+59
src/applications/people/editor/PhabricatorUserEditor.php
··· 494 494 } 495 495 496 496 497 + /** 498 + * Verify a user's email address. 499 + * 500 + * This verifies an individual email address. If the address is the user's 501 + * primary address and their account was not previously verified, their 502 + * account is marked as email verified. 503 + * 504 + * @task email 505 + */ 506 + public function verifyEmail( 507 + PhabricatorUser $user, 508 + PhabricatorUserEmail $email) { 509 + $actor = $this->requireActor(); 510 + 511 + if (!$user->getID()) { 512 + throw new Exception('User has not been created yet!'); 513 + } 514 + if (!$email->getID()) { 515 + throw new Exception('Email has not been created yet!'); 516 + } 517 + 518 + $user->openTransaction(); 519 + $user->beginWriteLocking(); 520 + 521 + $user->reload(); 522 + $email->reload(); 523 + 524 + if ($email->getUserPHID() != $user->getPHID()) { 525 + throw new Exception(pht('User does not own email!')); 526 + } 527 + 528 + if (!$email->getIsVerified()) { 529 + $email->setIsVerified(1); 530 + $email->save(); 531 + 532 + $log = PhabricatorUserLog::initializeNewLog( 533 + $actor, 534 + $user->getPHID(), 535 + PhabricatorUserLog::ACTION_EMAIL_VERIFY); 536 + $log->setNewValue($email->getAddress()); 537 + $log->save(); 538 + } 539 + 540 + if (!$user->getIsEmailVerified()) { 541 + // If the user just verified their primary email address, mark their 542 + // account as email verified. 543 + $user_primary = $user->loadPrimaryEmail(); 544 + if ($user_primary->getID() == $email->getID()) { 545 + $user->setIsEmailVerified(1); 546 + $user->save(); 547 + } 548 + } 549 + 550 + $user->endWriteLocking(); 551 + $user->saveTransaction(); 552 + 553 + } 554 + 555 + 497 556 /* -( Internals )---------------------------------------------------------- */ 498 557 499 558
+2
src/applications/people/storage/PhabricatorUserLog.php
··· 25 25 const ACTION_EMAIL_PRIMARY = 'email-primary'; 26 26 const ACTION_EMAIL_REMOVE = 'email-remove'; 27 27 const ACTION_EMAIL_ADD = 'email-add'; 28 + const ACTION_EMAIL_VERIFY = 'email-verify'; 28 29 29 30 const ACTION_CHANGE_PASSWORD = 'change-password'; 30 31 const ACTION_CHANGE_USERNAME = 'change-username'; ··· 67 68 self::ACTION_EMAIL_PRIMARY => pht('Email: Change Primary'), 68 69 self::ACTION_EMAIL_ADD => pht('Email: Add Address'), 69 70 self::ACTION_EMAIL_REMOVE => pht('Email: Remove Address'), 71 + self::ACTION_EMAIL_VERIFY => pht('Email: Verify'), 70 72 self::ACTION_CHANGE_PASSWORD => pht('Change Password'), 71 73 self::ACTION_CHANGE_USERNAME => pht('Change Username'), 72 74 self::ACTION_ENTER_HISEC => pht('Hisec: Enter'),