diff --git a/resources/sql/autopatches/20140515.trust-emails.sql b/resources/sql/autopatches/20140515.trust-emails.sql new file mode 100644 index 0000000000..8233f73542 --- /dev/null +++ b/resources/sql/autopatches/20140515.trust-emails.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_auth.auth_providerconfig + ADD `shouldTrustEmails` tinyint(1) NOT NULL DEFAULT 0 AFTER shouldAllowUnlink; diff --git a/src/applications/auth/controller/PhabricatorAuthRegisterController.php b/src/applications/auth/controller/PhabricatorAuthRegisterController.php index 563f256cc5..ffcb42d642 100644 --- a/src/applications/auth/controller/PhabricatorAuthRegisterController.php +++ b/src/applications/auth/controller/PhabricatorAuthRegisterController.php @@ -249,6 +249,11 @@ final class PhabricatorAuthRegisterController ($value_email === $default_email); } + if ($provider->shouldTrustEmails() && + $value_email === $default_email) { + $verify_email = true; + } + $email_obj = id(new PhabricatorUserEmail()) ->setAddress($value_email) ->setIsVerified((int)$verify_email); diff --git a/src/applications/auth/controller/config/PhabricatorAuthEditController.php b/src/applications/auth/controller/config/PhabricatorAuthEditController.php index 99be761000..846225b8ef 100644 --- a/src/applications/auth/controller/config/PhabricatorAuthEditController.php +++ b/src/applications/auth/controller/config/PhabricatorAuthEditController.php @@ -85,6 +85,7 @@ final class PhabricatorAuthEditController $v_registration = $config->getShouldAllowRegistration(); $v_link = $config->getShouldAllowLink(); $v_unlink = $config->getShouldAllowUnlink(); + $v_trust_email = $config->getShouldTrustEmails(); if ($request->isFormPost()) { @@ -120,6 +121,11 @@ final class PhabricatorAuthEditController PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK) ->setNewValue($request->getInt('allowUnlink', 0)); + $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) + ->setTransactionType( + PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS) + ->setNewValue($request->getInt('trustEmails', 0)); + foreach ($properties as $key => $value) { $xactions[] = id(new PhabricatorAuthProviderConfigTransaction()) ->setTransactionType( @@ -212,6 +218,13 @@ final class PhabricatorAuthEditController 'existing Phabricator accounts. If you disable this, Phabricator '. 'accounts will be permanently bound to provider accounts.')); + $str_trusted_email = hsprintf( + '%s: %s', + pht('Trust Email Addresses'), + pht( + 'Phabricator will skip email verification for accounts registered '. + 'through this provider.')); + $status_tag = id(new PHUITagView()) ->setType(PHUITagView::TYPE_STATE); if ($is_new) { @@ -262,6 +275,16 @@ final class PhabricatorAuthEditController $str_unlink, $v_unlink)); + if ($provider->shouldAllowEmailTrustConfiguration()) { + $form->appendChild( + id(new AphrontFormCheckboxControl()) + ->addCheckbox( + 'trustEmails', + 1, + $str_trusted_email, + $v_trust_email)); + } + $provider->extendEditForm($request, $form, $properties, $issues); $form diff --git a/src/applications/auth/editor/PhabricatorAuthProviderConfigEditor.php b/src/applications/auth/editor/PhabricatorAuthProviderConfigEditor.php index 5088519ce5..45f2106124 100644 --- a/src/applications/auth/editor/PhabricatorAuthProviderConfigEditor.php +++ b/src/applications/auth/editor/PhabricatorAuthProviderConfigEditor.php @@ -10,6 +10,7 @@ final class PhabricatorAuthProviderConfigEditor $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_LINK; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK; + $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS; $types[] = PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY; return $types; @@ -32,6 +33,8 @@ final class PhabricatorAuthProviderConfigEditor return (int)$object->getShouldAllowLink(); case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: return (int)$object->getShouldAllowUnlink(); + case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: + return (int)$object->getShouldTrustEmails(); case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: $key = $xaction->getMetadataValue( PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); @@ -48,6 +51,7 @@ final class PhabricatorAuthProviderConfigEditor case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: + case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: return $xaction->getNewValue(); } @@ -66,6 +70,8 @@ final class PhabricatorAuthProviderConfigEditor return $object->setShouldAllowLink($v); case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: return $object->setShouldAllowUnlink($v); + case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: + return $object->setShouldTrustEmails($v); case PhabricatorAuthProviderConfigTransaction::TYPE_PROPERTY: $key = $xaction->getMetadataValue( PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); @@ -89,6 +95,7 @@ final class PhabricatorAuthProviderConfigEditor case PhabricatorAuthProviderConfigTransaction::TYPE_REGISTRATION: case PhabricatorAuthProviderConfigTransaction::TYPE_LINK: case PhabricatorAuthProviderConfigTransaction::TYPE_UNLINK: + case PhabricatorAuthProviderConfigTransaction::TYPE_TRUST_EMAILS: // For these types, last transaction wins. return $v; } diff --git a/src/applications/auth/provider/PhabricatorAuthProvider.php b/src/applications/auth/provider/PhabricatorAuthProvider.php index ceb06fcfa7..9b44b294f3 100644 --- a/src/applications/auth/provider/PhabricatorAuthProvider.php +++ b/src/applications/auth/provider/PhabricatorAuthProvider.php @@ -141,6 +141,20 @@ abstract class PhabricatorAuthProvider { return $this->getProviderConfig()->getShouldAllowUnlink(); } + public function shouldTrustEmails() { + return $this->shouldAllowEmailTrustConfiguration() && + $this->getProviderConfig()->getShouldTrustEmails(); + } + + /** + * Should we allow the adapter to be marked as "trusted" + * This is true for all adapters except those that allow the user to type in + * emails (@see PhabricatorAuthProviderPassword) + */ + public function shouldAllowEmailTrustConfiguration() { + return true; + } + public function buildLoginForm( PhabricatorAuthStartController $controller) { return $this->renderLoginForm($controller->getRequest(), $mode = 'start'); diff --git a/src/applications/auth/provider/PhabricatorAuthProviderPassword.php b/src/applications/auth/provider/PhabricatorAuthProviderPassword.php index c7005e8bc6..80799ecebf 100644 --- a/src/applications/auth/provider/PhabricatorAuthProviderPassword.php +++ b/src/applications/auth/provider/PhabricatorAuthProviderPassword.php @@ -350,4 +350,7 @@ final class PhabricatorAuthProviderPassword return false; } + public function shouldAllowEmailTrustConfiguration() { + return false; + } } diff --git a/src/applications/auth/storage/PhabricatorAuthProviderConfig.php b/src/applications/auth/storage/PhabricatorAuthProviderConfig.php index 4678e2b170..a5ecffd58d 100644 --- a/src/applications/auth/storage/PhabricatorAuthProviderConfig.php +++ b/src/applications/auth/storage/PhabricatorAuthProviderConfig.php @@ -12,6 +12,7 @@ final class PhabricatorAuthProviderConfig extends PhabricatorAuthDAO protected $shouldAllowRegistration = 0; protected $shouldAllowLink = 0; protected $shouldAllowUnlink = 0; + protected $shouldTrustEmails = 0; protected $properties = array(); diff --git a/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php b/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php index bb02531e1c..f9cf6879d4 100644 --- a/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php +++ b/src/applications/auth/storage/PhabricatorAuthProviderConfigTransaction.php @@ -7,6 +7,7 @@ final class PhabricatorAuthProviderConfigTransaction const TYPE_REGISTRATION = 'config:registration'; const TYPE_LINK = 'config:link'; const TYPE_UNLINK = 'config:unlink'; + const TYPE_TRUST_EMAILS = "config:trustEmails"; const TYPE_PROPERTY = 'config:property'; const PROPERTY_KEY = 'auth:property'; @@ -121,6 +122,17 @@ final class PhabricatorAuthProviderConfigTransaction $this->renderHandleLink($author_phid)); } break; + case self::TYPE_TRUST_EMAILS: + if ($new) { + return pht( + '%s enabled email trust.', + $this->renderHandleLink($author_phid)); + } else { + return pht( + '%s disabled email trust.', + $this->renderHandleLink($author_phid)); + } + break; case self::TYPE_PROPERTY: $provider = $this->getProvider(); if ($provider) {