Differential D13125 Diff 31760 src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorEmailAddressesSettingsPanel.php
Show All 9 Lines | final class PhabricatorEmailAddressesSettingsPanel | ||||
public function getPanelName() { | public function getPanelName() { | ||||
return pht('Email Addresses'); | return pht('Email Addresses'); | ||||
} | } | ||||
public function getPanelGroup() { | public function getPanelGroup() { | ||||
return pht('Email'); | return pht('Email'); | ||||
} | } | ||||
public function isEditableByAdministrators() { | |||||
if ($this->getUser()->getIsMailingList()) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $user = $this->getUser(); | ||||
$editable = PhabricatorEnv::getEnvConfig('account.editable'); | $editable = PhabricatorEnv::getEnvConfig('account.editable'); | ||||
$uri = $request->getRequestURI(); | $uri = $request->getRequestURI(); | ||||
$uri->setQueryParams(array()); | $uri->setQueryParams(array()); | ||||
if ($editable) { | if ($editable) { | ||||
$new = $request->getStr('new'); | $new = $request->getStr('new'); | ||||
if ($new) { | if ($new) { | ||||
▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | public function processRequest(AphrontRequest $request) { | ||||
return $view; | return $view; | ||||
} | } | ||||
private function returnNewAddressResponse( | private function returnNewAddressResponse( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
PhutilURI $uri, | PhutilURI $uri, | ||||
$new) { | $new) { | ||||
$user = $request->getUser(); | $user = $this->getUser(); | ||||
$viewer = $this->getViewer(); | |||||
$e_email = true; | $e_email = true; | ||||
$email = null; | $email = null; | ||||
$errors = array(); | $errors = array(); | ||||
if ($request->isDialogFormPost()) { | if ($request->isDialogFormPost()) { | ||||
$email = trim($request->getStr('email')); | $email = trim($request->getStr('email')); | ||||
if ($new == 'verify') { | if ($new == 'verify') { | ||||
// The user clicked "Done" from the "an email has been sent" dialog. | // The user clicked "Done" from the "an email has been sent" dialog. | ||||
return id(new AphrontReloadResponse())->setURI($uri); | return id(new AphrontReloadResponse())->setURI($uri); | ||||
} | } | ||||
PhabricatorSystemActionEngine::willTakeAction( | PhabricatorSystemActionEngine::willTakeAction( | ||||
array($user->getPHID()), | array($viewer->getPHID()), | ||||
new PhabricatorSettingsAddEmailAction(), | new PhabricatorSettingsAddEmailAction(), | ||||
1); | 1); | ||||
if (!strlen($email)) { | if (!strlen($email)) { | ||||
$e_email = pht('Required'); | $e_email = pht('Required'); | ||||
$errors[] = pht('Email is required.'); | $errors[] = pht('Email is required.'); | ||||
} else if (!PhabricatorUserEmail::isValidAddress($email)) { | } else if (!PhabricatorUserEmail::isValidAddress($email)) { | ||||
$e_email = pht('Invalid'); | $e_email = pht('Invalid'); | ||||
Show All 13 Lines | if ($request->isDialogFormPost()) { | ||||
} | } | ||||
} | } | ||||
if (!$errors) { | if (!$errors) { | ||||
$object = id(new PhabricatorUserEmail()) | $object = id(new PhabricatorUserEmail()) | ||||
->setAddress($email) | ->setAddress($email) | ||||
->setIsVerified(0); | ->setIsVerified(0); | ||||
try { | // If an administrator is editing a mailing list, automatically verify | ||||
// the address. | |||||
if ($viewer->getPHID() != $user->getPHID()) { | |||||
if ($viewer->getIsAdmin()) { | |||||
$object->setIsVerified(1); | |||||
} | |||||
} | |||||
try { | |||||
id(new PhabricatorUserEditor()) | id(new PhabricatorUserEditor()) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->addEmail($user, $object); | ->addEmail($user, $object); | ||||
if ($object->getIsVerified()) { | |||||
// If we autoverified the address, just reload the page. | |||||
return id(new AphrontReloadResponse())->setURI($uri); | |||||
} | |||||
$object->sendVerificationEmail($user); | $object->sendVerificationEmail($user); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($user) | ||||
->addHiddenInput('new', 'verify') | ->addHiddenInput('new', 'verify') | ||||
->setTitle(pht('Verification Email Sent')) | ->setTitle(pht('Verification Email Sent')) | ||||
->appendChild(phutil_tag('p', array(), pht( | ->appendChild(phutil_tag('p', array(), pht( | ||||
'A verification email has been sent. Click the link in the '. | 'A verification email has been sent. Click the link in the '. | ||||
Show All 19 Lines | $form = id(new PHUIFormLayoutView()) | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setLabel(pht('Email')) | ->setLabel(pht('Email')) | ||||
->setName('email') | ->setName('email') | ||||
->setValue($email) | ->setValue($email) | ||||
->setCaption(PhabricatorUserEmail::describeAllowedAddresses()) | ->setCaption(PhabricatorUserEmail::describeAllowedAddresses()) | ||||
->setError($e_email)); | ->setError($e_email)); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->addHiddenInput('new', 'true') | ->addHiddenInput('new', 'true') | ||||
->setTitle(pht('New Address')) | ->setTitle(pht('New Address')) | ||||
->appendChild($errors) | ->appendChild($errors) | ||||
->appendChild($form) | ->appendChild($form) | ||||
->addSubmitButton(pht('Save')) | ->addSubmitButton(pht('Save')) | ||||
->addCancelButton($uri); | ->addCancelButton($uri); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
private function returnDeleteAddressResponse( | private function returnDeleteAddressResponse( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
PhutilURI $uri, | PhutilURI $uri, | ||||
$email_id) { | $email_id) { | ||||
$user = $this->getUser(); | |||||
$user = $request->getUser(); | $viewer = $this->getViewer(); | ||||
// NOTE: You can only delete your own email addresses, and you can not | // NOTE: You can only delete your own email addresses, and you can not | ||||
// delete your primary address. | // delete your primary address. | ||||
$email = id(new PhabricatorUserEmail())->loadOneWhere( | $email = id(new PhabricatorUserEmail())->loadOneWhere( | ||||
'id = %d AND userPHID = %s AND isPrimary = 0', | 'id = %d AND userPHID = %s AND isPrimary = 0', | ||||
$email_id, | $email_id, | ||||
$user->getPHID()); | $user->getPHID()); | ||||
if (!$email) { | if (!$email) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
id(new PhabricatorUserEditor()) | id(new PhabricatorUserEditor()) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->removeEmail($user, $email); | ->removeEmail($user, $email); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | return id(new AphrontRedirectResponse())->setURI($uri); | ||||
} | } | ||||
$address = $email->getAddress(); | $address = $email->getAddress(); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->addHiddenInput('delete', $email_id) | ->addHiddenInput('delete', $email_id) | ||||
->setTitle(pht("Really delete address '%s'?", $address)) | ->setTitle(pht("Really delete address '%s'?", $address)) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'Are you sure you want to delete this address? You will no '. | 'Are you sure you want to delete this address? You will no '. | ||||
'longer be able to use it to login.')) | 'longer be able to use it to login.')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'Note: Removing an email address from your account will invalidate '. | 'Note: Removing an email address from your account will invalidate '. | ||||
'any outstanding password reset links.')) | 'any outstanding password reset links.')) | ||||
->addSubmitButton(pht('Delete')) | ->addSubmitButton(pht('Delete')) | ||||
->addCancelButton($uri); | ->addCancelButton($uri); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
private function returnVerifyAddressResponse( | private function returnVerifyAddressResponse( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
PhutilURI $uri, | PhutilURI $uri, | ||||
$email_id) { | $email_id) { | ||||
$user = $this->getUser(); | |||||
$user = $request->getUser(); | $viewer = $this->getViewer(); | ||||
// NOTE: You can only send more email for your unverified addresses. | // NOTE: You can only send more email for your unverified addresses. | ||||
$email = id(new PhabricatorUserEmail())->loadOneWhere( | $email = id(new PhabricatorUserEmail())->loadOneWhere( | ||||
'id = %d AND userPHID = %s AND isVerified = 0', | 'id = %d AND userPHID = %s AND isVerified = 0', | ||||
$email_id, | $email_id, | ||||
$user->getPHID()); | $user->getPHID()); | ||||
if (!$email) { | if (!$email) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$email->sendVerificationEmail($user); | $email->sendVerificationEmail($user); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | return id(new AphrontRedirectResponse())->setURI($uri); | ||||
} | } | ||||
$address = $email->getAddress(); | $address = $email->getAddress(); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->addHiddenInput('verify', $email_id) | ->addHiddenInput('verify', $email_id) | ||||
->setTitle(pht('Send Another Verification Email?')) | ->setTitle(pht('Send Another Verification Email?')) | ||||
->appendChild(phutil_tag('p', array(), pht( | ->appendChild(phutil_tag('p', array(), pht( | ||||
'Send another copy of the verification email to %s?', | 'Send another copy of the verification email to %s?', | ||||
$address))) | $address))) | ||||
->addSubmitButton(pht('Send Email')) | ->addSubmitButton(pht('Send Email')) | ||||
->addCancelButton($uri); | ->addCancelButton($uri); | ||||
return id(new AphrontDialogResponse())->setDialog($dialog); | return id(new AphrontDialogResponse())->setDialog($dialog); | ||||
} | } | ||||
private function returnPrimaryAddressResponse( | private function returnPrimaryAddressResponse( | ||||
AphrontRequest $request, | AphrontRequest $request, | ||||
PhutilURI $uri, | PhutilURI $uri, | ||||
$email_id) { | $email_id) { | ||||
$user = $this->getUser(); | |||||
$user = $request->getUser(); | $viewer = $this->getViewer(); | ||||
$token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | $token = id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | ||||
$user, | $viewer, | ||||
$request, | $request, | ||||
$this->getPanelURI()); | $this->getPanelURI()); | ||||
// NOTE: You can only make your own verified addresses primary. | // NOTE: You can only make your own verified addresses primary. | ||||
$email = id(new PhabricatorUserEmail())->loadOneWhere( | $email = id(new PhabricatorUserEmail())->loadOneWhere( | ||||
'id = %d AND userPHID = %s AND isVerified = 1 AND isPrimary = 0', | 'id = %d AND userPHID = %s AND isVerified = 1 AND isPrimary = 0', | ||||
$email_id, | $email_id, | ||||
$user->getPHID()); | $user->getPHID()); | ||||
if (!$email) { | if (!$email) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
id(new PhabricatorUserEditor()) | id(new PhabricatorUserEditor()) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->changePrimaryEmail($user, $email); | ->changePrimaryEmail($user, $email); | ||||
return id(new AphrontRedirectResponse())->setURI($uri); | return id(new AphrontRedirectResponse())->setURI($uri); | ||||
} | } | ||||
$address = $email->getAddress(); | $address = $email->getAddress(); | ||||
$dialog = id(new AphrontDialogView()) | $dialog = id(new AphrontDialogView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->addHiddenInput('primary', $email_id) | ->addHiddenInput('primary', $email_id) | ||||
->setTitle(pht('Change primary email address?')) | ->setTitle(pht('Change primary email address?')) | ||||
->appendParagraph( | ->appendParagraph( | ||||
pht( | pht( | ||||
'If you change your primary address, Phabricator will send all '. | 'If you change your primary address, Phabricator will send all '. | ||||
'email to %s.', | 'email to %s.', | ||||
$address)) | $address)) | ||||
->appendParagraph( | ->appendParagraph( | ||||
Show All 10 Lines |