1
0
AntonLV 2 жил өмнө
parent
commit
4257c73fd4

+ 3 - 2
inc/classes/BxDolTwilio.php

@@ -7,6 +7,8 @@
  * @{
  */
 
+require_once BX_DIRECTORY_PATH_PLUGINS . 'twilio/sdk/src/Twilio/autoload.php';
+
 class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
 {
     protected $_sSid;
@@ -47,8 +49,7 @@ class BxDolTwilio extends BxDolFactory implements iBxDolSingleton
     
     public function sendSms($sTo, $sMessage, $sFrom = '')
     {
-        try{
-            require_once BX_DIRECTORY_PATH_PLUGINS . 'Twilio/sdk/src/Twilio/autoload.php'; // Loads the library
+        try {
             $client = new Twilio\Rest\Client($this->_sSid, $this->_sToken);
             $aParams = array('body' => $sMessage, 'from' => $sFrom != '' ? $this->normalizePhone($sFrom) : $this->normalizePhone($this->_sFromNumber));
             $client->messages->create($this->normalizePhone($sTo), $aParams);

+ 15 - 14
template/scripts/BxBaseServiceAccount.php

@@ -417,9 +417,8 @@ class BxBaseServiceAccount extends BxDol
             $sPhoneNumber = $a['phone'];
             
             $oSession = BxDolSession::getInstance();           
-            if ($sPhoneNumber != "" && $oSession->isValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE)){
-                 $iStep = 2;
-            }
+            if ($sPhoneNumber != "" && $oSession->isValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE))
+                $iStep = 2;
         
             if (bx_get('step'))
                 $iStep = (int)bx_get('step');
@@ -430,12 +429,14 @@ class BxBaseServiceAccount extends BxDol
                 if (!$oForm)
                     return MsgBox(_t("_sys_txt_confirm_phone_set_phone_error_occured"));
             
-                $oForm->initChecker(array('phone' => $sPhoneNumber));
+                $oForm->initChecker(['phone' => $sPhoneNumber]);
                 if ($oForm->isSubmittedAndValid()) {
-                    $oAccount->updatePhone(trim($oForm->getCleanValue('phone')));
+                    $sPhoneNumber = trim($oForm->getCleanValue('phone'));
+                    $oAccount->updatePhone($sPhoneNumber);
+
                     $sActivationCode = rand(1000, 9999);
                     $sActivationText =_t('_sys_txt_confirm_phone_sms_text', $sActivationCode);
-                    $ret = null;
+                    $mixedResult = null;
                     /**
                      * @hooks
                      * @hookdef hook-account-before_confirm_phone_send_sms 'account', 'before_confirm_phone_send_sms' - hook in confirm phone 
@@ -449,14 +450,14 @@ class BxBaseServiceAccount extends BxDol
                      *      - `override_result` - [mixed] by ref, can be object, can be overridden in hook processing
                      * @hook @ref hook-account-before_confirm_phone_send_sms
                      */
-                    bx_alert('account', 'before_confirm_phone_send_sms', $oAccount->id(), bx_get_logged_profile_id(), array('phone_number' => $sPhoneNumber, 'sms_text' => $sActivationText, 'override_result' => &$ret));
-                    if ($ret === null) 
-                    {
-                        $oTwilio = BxDolTwilio::getInstance();
-                        if(!$oTwilio->sendSms($sPhoneNumber,  $sActivationText)){
-                            return MsgBox(_t("_sys_txt_confirm_phone_send_sms_error_occured"));
-                        }
-                    }
+                    bx_alert('account', 'before_confirm_phone_send_sms', $oAccount->id(), bx_get_logged_profile_id(), [
+                        'phone_number' => $sPhoneNumber, 
+                        'sms_text' => $sActivationText, 
+                        'override_result' => &$mixedResult
+                    ]);
+
+                    if ($mixedResult === null && !BxDolTwilio::getInstance()->sendSms($sPhoneNumber,  $sActivationText))
+                        return MsgBox(_t("_sys_txt_confirm_phone_send_sms_error_occured"));
 
                     $oSession->setValue(BX_ACCOUNT_SESSION_KEY_FOR_PHONE_ACTIVATEION_CODE, $sActivationCode);
                     header('Location: ' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-phone')));