@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
at recaptime-dev/main 67 lines 1.9 kB view raw
1<?php 2 3final class PhabricatorAuthContactNumberTestController 4 extends PhabricatorAuthContactNumberController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getViewer(); 8 $id = $request->getURIData('id'); 9 10 $sms_auth_factor = new PhabricatorSMSAuthFactor(); 11 if ($sms_auth_factor->isSMSMailerConfigured()) { 12 $number = id(new PhabricatorAuthContactNumberQuery()) 13 ->setViewer($viewer) 14 ->withIDs(array($id)) 15 ->requireCapabilities( 16 array( 17 PhabricatorPolicyCapability::CAN_VIEW, 18 PhabricatorPolicyCapability::CAN_EDIT, 19 )) 20 ->executeOne(); 21 } 22 if (!isset($number) || !$number) { 23 return new Aphront404Response(); 24 } 25 26 $id = $number->getID(); 27 $cancel_uri = $number->getURI(); 28 29 // NOTE: This is a global limit shared by all users. 30 PhabricatorSystemActionEngine::willTakeAction( 31 array(id(new PhabricatorAuthApplication())->getPHID()), 32 new PhabricatorAuthTestSMSAction(), 33 1); 34 35 if ($request->isFormPost()) { 36 $uri = PhabricatorEnv::getURI('/'); 37 $uri = new PhutilURI($uri); 38 39 $mail = id(new PhabricatorMetaMTAMail()) 40 ->setMessageType(PhabricatorMailSMSMessage::MESSAGETYPE) 41 ->addTos(array($viewer->getPHID())) 42 ->setSensitiveContent(false) 43 ->setBody( 44 pht( 45 'This is a terse test text message (from "%s").', 46 $uri->getDomain())) 47 ->save(); 48 49 return id(new AphrontRedirectResponse())->setURI($mail->getURI()); 50 } 51 52 $number_display = phutil_tag( 53 'strong', 54 array(), 55 $number->getDisplayName()); 56 57 return $this->newDialog() 58 ->setTitle(pht('Set Test Message')) 59 ->appendParagraph( 60 pht( 61 'Send a test message to %s?', 62 $number_display)) 63 ->addSubmitButton(pht('Send SMS')) 64 ->addCancelButton($cancel_uri); 65 } 66 67}