Пример #1
0
 function Update($ID, $arFields)
 {
     global $DB, $USER_FIELD_MANAGER;
     $ID = intval($ID);
     if (!$this->CheckFields($arFields, $ID)) {
         $Result = false;
         $arFields["RESULT_MESSAGE"] =& $this->LAST_ERROR;
     } else {
         unset($arFields["ID"]);
         if (is_set($arFields, "ACTIVE") && $arFields["ACTIVE"] != "Y") {
             $arFields["ACTIVE"] = "N";
         }
         if (is_set($arFields, "PERSONAL_GENDER") && ($arFields["PERSONAL_GENDER"] != "M" && $arFields["PERSONAL_GENDER"] != "F")) {
             $arFields["PERSONAL_GENDER"] = "";
         }
         if (is_set($arFields, "PASSWORD")) {
             $original_pass = $arFields["PASSWORD"];
             $salt = randString(8, array("abcdefghijklnmopqrstuvwxyz", "ABCDEFGHIJKLNMOPQRSTUVWXYZ", "0123456789", ",.<>/?;:[]{}\\|~!@#\$%^&*()-_+="));
             $arFields["PASSWORD"] = $salt . md5($salt . $arFields["PASSWORD"]);
             $rUser = CUser::GetByID($ID);
             if ($arUser = $rUser->Fetch()) {
                 if ($arUser["PASSWORD"] != $arFields["PASSWORD"]) {
                     $DB->Query("DELETE FROM b_user_stored_auth WHERE USER_ID=" . $ID);
                 }
             }
             if (COption::GetOptionString("main", "event_log_password_change", "N") === "Y") {
                 CEventLog::Log("SECURITY", "USER_PASSWORD_CHANGED", "main", $ID);
             }
             //$arFields["STORED_HASH"] = CUser::GetPasswordHash($arFields["PASSWORD"]);
         }
         unset($arFields["STORED_HASH"]);
         $checkword = '';
         if (!is_set($arFields, "CHECKWORD")) {
             if (is_set($arFields, "PASSWORD") || is_set($arFields, "EMAIL") || is_set($arFields, "LOGIN") || is_set($arFields, "ACTIVE")) {
                 $salt = randString(8);
                 $checkword = md5(CMain::GetServerUniqID() . uniqid());
                 $arFields["CHECKWORD"] = $salt . md5($salt . $checkword);
             }
         } else {
             $salt = randString(8);
             $checkword = $arFields["CHECKWORD"];
             $arFields["CHECKWORD"] = $salt . md5($salt . $checkword);
         }
         if (is_set($arFields, "CHECKWORD") && !is_set($arFields, "CHECKWORD_TIME")) {
             $arFields["~CHECKWORD_TIME"] = $DB->CurrentTimeFunction();
         }
         if (is_set($arFields, "WORK_COUNTRY")) {
             $arFields["WORK_COUNTRY"] = IntVal($arFields["WORK_COUNTRY"]);
         }
         if (is_set($arFields, "PERSONAL_COUNTRY")) {
             $arFields["PERSONAL_COUNTRY"] = IntVal($arFields["PERSONAL_COUNTRY"]);
         }
         if (array_key_exists("PERSONAL_PHOTO", $arFields) && is_array($arFields["PERSONAL_PHOTO"]) && (!array_key_exists("MODULE_ID", $arFields["PERSONAL_PHOTO"]) || strlen($arFields["PERSONAL_PHOTO"]["MODULE_ID"]) <= 0)) {
             $arFields["PERSONAL_PHOTO"]["MODULE_ID"] = "main";
         }
         CFile::SaveForDB($arFields, "PERSONAL_PHOTO", "main");
         if (array_key_exists("WORK_LOGO", $arFields) && is_array($arFields["WORK_LOGO"]) && (!array_key_exists("MODULE_ID", $arFields["WORK_LOGO"]) || strlen($arFields["WORK_LOGO"]["MODULE_ID"]) <= 0)) {
             $arFields["WORK_LOGO"]["MODULE_ID"] = "main";
         }
         CFile::SaveForDB($arFields, "WORK_LOGO", "main");
         $strUpdate = $DB->PrepareUpdate("b_user", $arFields);
         if (!is_set($arFields, "TIMESTAMP_X")) {
             $strUpdate .= ($strUpdate != "" ? "," : "") . " TIMESTAMP_X = " . $DB->GetNowFunction();
         }
         $strSql = "UPDATE b_user SET " . $strUpdate . " WHERE ID=" . $ID;
         $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
         $USER_FIELD_MANAGER->Update("USER", $ID, $arFields);
         if (COption::GetOptionString("main", "event_log_user_edit", "N") === "Y") {
             $res_log["user"] = $arFields["NAME"] != "" || $arFields["LAST_NAME"] != "" ? trim($arFields["NAME"] . " " . $arFields["LAST_NAME"]) : $arFields["LOGIN"];
             CEventLog::Log("SECURITY", "USER_EDIT", "main", $ID, serialize($res_log));
         }
         if (is_set($arFields, "GROUP_ID")) {
             CUser::SetUserGroup($ID, $arFields["GROUP_ID"]);
         }
         //update digest hash for http digest authorization
         if (is_set($arFields, "PASSWORD") && COption::GetOptionString('main', 'use_digest_auth', 'N') == 'Y') {
             CUser::UpdateDigest($arUser["ID"], $original_pass);
         }
         $Result = true;
         $arFields["CHECKWORD"] = $checkword;
         //update session information and cache for current user
         global $USER;
         if (is_object($USER) && $USER->GetID() == $ID) {
             static $arSessFields = array('LOGIN' => 'LOGIN', 'EMAIL' => 'EMAIL', 'FIRST_NAME' => 'NAME', 'SECOND_NAME' => 'SECOND_NAME', 'LAST_NAME' => 'LAST_NAME', 'AUTO_TIME_ZONE' => 'AUTO_TIME_ZONE', 'TIME_ZONE' => 'TIME_ZONE');
             foreach ($arSessFields as $key => $val) {
                 if (isset($arFields[$val])) {
                     $USER->SetParam($key, $arFields[$val]);
                 }
             }
             $name = $USER->GetParam("FIRST_NAME");
             $last_name = $USER->GetParam("LAST_NAME");
             $USER->SetParam("NAME", $name . ($name == '' || $last_name == '' ? "" : " ") . $last_name);
             //cache for GetByID()
             self::$CURRENT_USER = false;
         }
     }
     $arFields["ID"] = $ID;
     $arFields["RESULT"] =& $Result;
     $events = GetModuleEvents("main", "OnAfterUserUpdate");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$arFields));
     }
     if (defined("BX_COMP_MANAGED_CACHE")) {
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("USER_CARD_" . intval($ID / 100));
         $GLOBALS["CACHE_MANAGER"]->ClearByTag("USER_CARD");
     }
     return $Result;
 }
Пример #2
0
 public static function clearUserGroupCache($ID = false)
 {
     if ($ID === false) {
         self::$userGroupCache = array();
     } else {
         $ID = (int) $ID;
         if (isset(self::$userGroupCache[$ID])) {
             unset(self::$userGroupCache[$ID]);
         }
     }
 }