mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-27 23:18:20 +01:00
ef85f49adc
Summary: This commit doesn't change license of any file. It just makes the license implicit (inherited from LICENSE file in the root directory). We are removing the headers for these reasons: - It wastes space in editors, less code is visible in editor upon opening a file. - It brings noise to diff of the first change of any file every year. - It confuses Git file copy detection when creating small files. - We don't have an explicit license header in other files (JS, CSS, images, documentation). - Using license header in every file is not obligatory: http://www.apache.org/dev/apply-license.html#new. This change is approved by Alma Chao (Lead Open Source and IP Counsel at Facebook). Test Plan: Verified that the license survived only in LICENSE file and that it didn't modify externals. Reviewers: epriestley, davidrecordon Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2035 Differential Revision: https://secure.phabricator.com/D3886
199 lines
4.7 KiB
PHP
199 lines
4.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @task restrictions Domain Restrictions
|
|
* @task email Email About Email
|
|
*/
|
|
final class PhabricatorUserEmail extends PhabricatorUserDAO {
|
|
|
|
protected $userPHID;
|
|
protected $address;
|
|
protected $isVerified;
|
|
protected $isPrimary;
|
|
protected $verificationCode;
|
|
|
|
public function getVerificationURI() {
|
|
return '/emailverify/'.$this->getVerificationCode().'/';
|
|
}
|
|
|
|
public function save() {
|
|
if (!$this->verificationCode) {
|
|
$this->setVerificationCode(Filesystem::readRandomCharacters(24));
|
|
}
|
|
return parent::save();
|
|
}
|
|
|
|
|
|
/* -( Domain Restrictions )------------------------------------------------ */
|
|
|
|
|
|
/**
|
|
* @task restrictions
|
|
*/
|
|
public static function isAllowedAddress($address) {
|
|
$allowed_domains = PhabricatorEnv::getEnvConfig('auth.email-domains');
|
|
if (!$allowed_domains) {
|
|
return true;
|
|
}
|
|
|
|
$addr_obj = new PhutilEmailAddress($address);
|
|
|
|
$domain = $addr_obj->getDomainName();
|
|
if (!$domain) {
|
|
return false;
|
|
}
|
|
|
|
return in_array($domain, $allowed_domains);
|
|
}
|
|
|
|
|
|
/**
|
|
* @task restrictions
|
|
*/
|
|
public static function describeAllowedAddresses() {
|
|
$domains = PhabricatorEnv::getEnvConfig('auth.email-domains');
|
|
if (!$domains) {
|
|
return null;
|
|
}
|
|
|
|
if (count($domains) == 1) {
|
|
return 'Email address must be @'.head($domains);
|
|
} else {
|
|
return 'Email address must be at one of: '.
|
|
implode(', ', $domains);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Check if this install requires email verification.
|
|
*
|
|
* @return bool True if email addresses must be verified.
|
|
*
|
|
* @task restrictions
|
|
*/
|
|
public static function isEmailVerificationRequired() {
|
|
// NOTE: Configuring required email domains implies required verification.
|
|
return PhabricatorEnv::getEnvConfig('auth.require-email-verification') ||
|
|
PhabricatorEnv::getEnvConfig('auth.email-domains');
|
|
}
|
|
|
|
|
|
/* -( Email About Email )-------------------------------------------------- */
|
|
|
|
|
|
/**
|
|
* Send a verification email from $user to this address.
|
|
*
|
|
* @param PhabricatorUser The user sending the verification.
|
|
* @return this
|
|
* @task email
|
|
*/
|
|
public function sendVerificationEmail(PhabricatorUser $user) {
|
|
$username = $user->getUsername();
|
|
|
|
$address = $this->getAddress();
|
|
$link = PhabricatorEnv::getProductionURI($this->getVerificationURI());
|
|
|
|
|
|
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
|
|
|
$signature = null;
|
|
if (!$is_serious) {
|
|
$signature = <<<EOSIGNATURE
|
|
Get Well Soon,
|
|
Phabricator
|
|
EOSIGNATURE;
|
|
}
|
|
|
|
$body = <<<EOBODY
|
|
Hi {$username},
|
|
|
|
Please verify that you own this email address ({$address}) by clicking this
|
|
link:
|
|
|
|
{$link}
|
|
|
|
{$signature}
|
|
EOBODY;
|
|
|
|
id(new PhabricatorMetaMTAMail())
|
|
->addRawTos(array($address))
|
|
->setSubject('[Phabricator] Email Verification')
|
|
->setBody($body)
|
|
->setRelatedPHID($user->getPHID())
|
|
->saveAndSend();
|
|
|
|
return $this;
|
|
}
|
|
|
|
|
|
/**
|
|
* Send a notification email from $user to this address, informing the
|
|
* recipient that this is no longer their account's primary address.
|
|
*
|
|
* @param PhabricatorUser The user sending the notification.
|
|
* @param PhabricatorUserEmail New primary email address.
|
|
* @return this
|
|
* @task email
|
|
*/
|
|
public function sendOldPrimaryEmail(
|
|
PhabricatorUser $user,
|
|
PhabricatorUserEmail $new) {
|
|
$username = $user->getUsername();
|
|
|
|
$old_address = $this->getAddress();
|
|
$new_address = $new->getAddress();
|
|
|
|
$body = <<<EOBODY
|
|
Hi {$username},
|
|
|
|
This email address ({$old_address}) is no longer your primary email address.
|
|
Going forward, Phabricator will send all email to your new primary email
|
|
address ({$new_address}).
|
|
|
|
EOBODY;
|
|
|
|
id(new PhabricatorMetaMTAMail())
|
|
->addRawTos(array($old_address))
|
|
->setSubject('[Phabricator] Primary Address Changed')
|
|
->setBody($body)
|
|
->setFrom($user->getPHID())
|
|
->setRelatedPHID($user->getPHID())
|
|
->saveAndSend();
|
|
}
|
|
|
|
|
|
/**
|
|
* Send a notification email from $user to this address, informing the
|
|
* recipient that this is now their account's new primary email address.
|
|
*
|
|
* @param PhabricatorUser The user sending the verification.
|
|
* @return this
|
|
* @task email
|
|
*/
|
|
public function sendNewPrimaryEmail(PhabricatorUser $user) {
|
|
$username = $user->getUsername();
|
|
|
|
$new_address = $this->getAddress();
|
|
|
|
$body = <<<EOBODY
|
|
Hi {$username},
|
|
|
|
This is now your primary email address ({$new_address}). Going forward,
|
|
Phabricator will send all email here.
|
|
|
|
EOBODY;
|
|
|
|
id(new PhabricatorMetaMTAMail())
|
|
->addRawTos(array($new_address))
|
|
->setSubject('[Phabricator] Primary Address Changed')
|
|
->setBody($body)
|
|
->setFrom($user->getPHID())
|
|
->setRelatedPHID($user->getPHID())
|
|
->saveAndSend();
|
|
|
|
return $this;
|
|
}
|
|
|
|
}
|