Ejemplo n.º 1
0
 public static function onUserUpdate($arFields)
 {
     if ($arFields['RESULT'] && isset($arFields['ACTIVE']) && $arFields['ACTIVE'] == 'N') {
         $selectResult = CMailbox::getList(array(), array('USER_ID' => intval($arFields['ID']), 'ACTIVE' => 'Y'));
         while ($mailbox = $selectResult->fetch()) {
             CMailbox::update($mailbox['ID'], array('ACTIVE' => 'N'));
         }
     }
 }
Ejemplo n.º 2
0
 public static function delete($primary)
 {
     $serviceForDelete = static::getByPrimary($primary)->fetch();
     if (!$serviceForDelete) {
         $deleteResult = new Entity\DeleteResult();
         $deleteResult->addError(new Entity\EntityError(Localization\Loc::getMessage('mail_mailservice_not_found')));
         return $deleteResult;
     }
     $deleteResult = parent::delete($primary);
     if ($deleteResult->isSuccess()) {
         $serviceId = is_array($primary) ? $primary['ID'] : $primary;
         if (in_array($serviceForDelete['SERVICE_TYPE'], array('controller', 'domain'))) {
             $mbData = array('ACTIVE' => 'N', 'SERVICE_ID' => 0);
         } else {
             $emptyService = static::getList(array('filter' => array('=SITE_ID' => $serviceForDelete['SITE_ID'], 'ACTIVE' => 'Y', '=SERVER' => '', '=PORT' => '', '=ENCRYPTION' => '', '=LINK' => ''), 'limit' => 1))->fetch();
             $mbData = $emptyService ? array('SERVICE_ID' => $emptyService['ID'], 'NAME' => $emptyService['NAME']) : array('ACTIVE' => 'N', 'SERVICE_ID' => 0);
         }
         $selectResult = \CMailbox::getList(array(), array('SERVICE_ID' => $serviceId));
         while ($mailbox = $selectResult->fetch()) {
             \CMailbox::update($mailbox['ID'], $mbData);
         }
     }
     return $deleteResult;
 }
Ejemplo n.º 3
0
 private static function executeChangePassword(&$error)
 {
     global $USER;
     $error = false;
     $password = $_REQUEST['password'];
     $password2 = $_REQUEST['password2'];
     if (!check_bitrix_sessid()) {
         $error = GetMessage('INTR_MAIL_CSRF');
     }
     if ($error === false) {
         $mailbox = CIntranetMailSetupHelper::getUserMailbox($USER->GetID());
         if (empty($mailbox) || !in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain', 'imap'))) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         if ($mailbox['ID'] != $_REQUEST['ID']) {
             $error = GetMessage('INTR_MAIL_FORM_ERROR');
         }
     }
     if ($error === false) {
         if (in_array($mailbox['SERVER_TYPE'], array('controller', 'domain', 'crdomain')) && $password != $password2) {
             $error = GetMessage('INTR_MAIL_INP_PASSWORD2_BAD');
         }
     }
     if ($error === false) {
         if ($mailbox['SERVER_TYPE'] == 'crdomain') {
             list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
             $crResponse = CControllerClient::ExecuteEvent('OnMailControllerChangeMemberPassword', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password));
             if (!isset($crResponse['result'])) {
                 $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
             }
         } else {
             if ($mailbox['SERVER_TYPE'] == 'domain') {
                 $domainService = CIntranetMailSetupHelper::getDomainService($mailbox['SERVICE_ID']);
                 list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                 $result = CMailDomain2::changePassword($domainService['token'], $domain, $login, $password, $error);
                 if (is_null($result)) {
                     $error = CMail::getErrorMessage($error);
                 }
             } else {
                 if ($mailbox['SERVER_TYPE'] == 'controller') {
                     list($login, $domain) = explode('@', $mailbox['LOGIN'], 2);
                     $crResponse = CControllerClient::ExecuteEvent('OnMailControllerChangePassword', array('DOMAIN' => $domain, 'NAME' => $login, 'PASSWORD' => $password));
                     if (!isset($crResponse['result'])) {
                         $error = empty($crResponse['error']) ? GetMessage('INTR_MAIL_CONTROLLER_INVALID') : CMail::getErrorMessage($crResponse['error']);
                     }
                 } else {
                     if ($mailbox['SERVER_TYPE'] == 'imap') {
                         $unseen = CMailUtil::CheckImapMailbox($mailbox['SERVER'], $mailbox['PORT'], $mailbox['USE_TLS'], $mailbox['LOGIN'], $password, $error, 30);
                         if ($error === false) {
                             $res = CMailbox::update($mailbox['ID'], array('PASSWORD' => $password));
                             if (!$res) {
                                 $error = GetMessage('INTR_MAIL_SAVE_ERROR');
                             }
                         }
                     }
                 }
             }
         }
     }
     return array('result' => $error === false ? 'ok' : 'error', 'error' => CharsetConverter::ConvertCharset($error, SITE_CHARSET, 'UTF-8'));
 }