/** * @param $arFields * @return bool */ public static function update($arFields) { /** * @global CMain $APPLICATION * @global CDataBase $DB */ global $DB, $APPLICATION; $aMsg = array(); $USER_ID = intval($arFields["USER_ID"]); if($USER_ID) { if($arFields["ACTIVE"]!=="Y") { CSecurityUser::deactivate($USER_ID); } else { $secret = substr(trim($arFields["SECRET"]), 0, 64); if(strlen($secret) <= 0) { CSecurityUser::delete($USER_ID); } else { $arKey = self::getSecurityUserInfo($USER_ID); if($arKey && ($arKey["SECRET"] == $secret)) $cnt = intval($arKey["COUNTER"]); else $cnt = 0; $sync1 = trim($arFields["SYNC1"]); $sync2 = trim($arFields["SYNC2"]); if($sync1 || $sync2) { $bin_secret = pack('H*', $secret); $cnt = CSecurityUser::getSyncCounter($bin_secret, $sync1, $sync2, $aMsg); } if($arKey) { $DB->Query(" UPDATE b_sec_user SET ACTIVE = 'Y', SECRET = '".$DB->ForSQL($secret)."', COUNTER = ".$cnt." WHERE USER_ID = ".$USER_ID." "); } else { $DB->Query(" INSERT INTO b_sec_user ( USER_ID, ACTIVE, SECRET, COUNTER ) VALUES ( ".$USER_ID.", 'Y', '".$DB->ForSQL($secret)."', ".$cnt.") "); } } } } if(count($aMsg) > 0) { $e = new CAdminException($aMsg); $APPLICATION->ThrowException($e); return false; } return true; }