addUser

при регистрации пользователя, есть птичка (подписаться на новости)

20.03.2013 Bitrix, php скрипты No comments , , , ,

при регистрации пользователя, есть птичка (подписаться на новости)

// Подписка на рассылку при регистрации

AddEventHandler("main", "OnAfterUserAdd", "OnAfterUserAddHandler");

function OnAfterUserAddHandler(&$arFields)
{

   $errors = Array();

   if($arFields["ID"]>0 && $arFields["UF_SUBSCRIBE"])
   {

      if(CModule::IncludeModule("subscribe")) {
      
         $USER_ID = $arFields["ID"];
         $EMAIL = $arFields["EMAIL"];
      
         $arFilter = array(
            "ACTIVE" => "Y",
            "LID" => "s1",
            "VISIBLE"=>"Y",
         );
      
         $rsRubrics = CRubric::GetList(array(), $arFilter);
         $arRubrics = array();
         while($arRubric = $rsRubrics->GetNext()) $arRubrics[] = $arRubric["ID"];
      
         $obSubscription = new CSubscription;
      
         $rsSubscription = $obSubscription->GetList(array(), array("USER_ID" => $USER_ID));
         $arSubscription = $rsSubscription->Fetch();
   
         if(is_array($arSubscription))
         {
            $rs = $obSubscription->Update(
               $arSubscription["ID"],
               array(
                  "FORMAT" => "html",
                  "RUB_ID" => $arRubrics,
               ),
               false
            );
         }
         else
         {
            $ID = $obSubscription->Add(array(
               "USER_ID" => $USER_ID,
               "ACTIVE" => "Y",
               "EMAIL" => $EMAIL,
               "FORMAT" => "html",
               "CONFIRMED" => "Y",
               "SEND_CONFIRM" => "N",
               "RUB_ID" => $arRubrics,
            ));
         }
      
      }
      
   }
   

}

Быстрая регистрация пользователя

21.02.2013 Bitrix, php скрипты No comments ,

function simpleRegister($strMail){

 global $APPLICATION, $USER, $DB;
 
 // стандартная процедура регистрации пользователя
 $bConfirmReq = COption::GetOptionString("main", "new_user_registration_email_confirmation", "N") == "Y";

 $arUser["PASSWORD"]     = randString(music);
 $arUser["LOGIN"]           = $strMail;
 $arUser["EMAIL"]           = $strMail;
 $arUser["LAST_NAME"]       = '';
 $arUser["SECOND_NAME"]     = '';
 $arUser["PERSONAL_PHONE"]  = '';
 $arUser["NAME"]            = '';  
 $arUser["CHECKWORD"]       = randString(music);
 $arUser["~CHECKWORD_TIME"] = $DB->CurrentTimeFunction();
 $arUser["ACTIVE"]          = $bConfirmReq? "N": "Y";
 $arUser["CONFIRM_CODE"]    = $bConfirmReq? randString(music): "";
 $arUser["LID"]             = SITE_ID;
 $arUser["USER_IP"]         = $_SERVER["REMOTE_ADDR"];
 $arUser["USER_HOST"]       = @gethostbyaddr($REMOTE_ADDR);
   
 if($arUser["AUTO_TIME_ZONE"] <> "Y" && $arUser["AUTO_TIME_ZONE"] <> "N")
  $arUser["AUTO_TIME_ZONE"] = "";

 $def_group = COption::GetOptionString("main", "new_user_registration_def_group", "");
 if($def_group != "")
  $arUser["GROUP_ID"] = explode(",", $def_group);

 $bOk = true;

 $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("USER", $arUser);

 $events = GetModuleEvents("main", "OnBeforeUserRegister");
 while($arEvent = $events->Fetch())
 {
  if(ExecuteModuleEventEx($arEvent, array(&$arUser)) === false)
  {
  if($err = $APPLICATION->GetException())
   $arErr[] = $err->GetString();
   $bOk = false;
   break;
  }
 }
   
 
 
 if ($bOk)
 {
  $user = new CUser();
  if($ID  = $user->Add($arUser)){
   //$USER->Authorize($ID);
   $event = new CEvent;
   $event->SendImmediate("USER_INVITE", SITE_ID, $arUser);
   if(COption::GetOptionString("main", "event_log_register", "N") === "Y")
    CEventLog::Log("SECURITY", "USER_REGISTER", "main", $ID);
  }  
  return true;
 }else{
  return false;
 }
 
 

}

Функа для проверки пользователя по эл. почте

21.02.2013 Bitrix No comments ,

function checkUserExist($strMail){

 $filter = Array("EMAIL" => $strMail);
 $rsUsers = CUser::GetList(($by="personal_country"), ($order="desc"), $filter); // выбираем пользователей  
 if($user = $rsUsers->GetNext()){
  return true;
 }else{
  return false;
 }

}

Создание юзера

24.03.2012 Bitrix 1 comment ,

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$user = new CUser;

	$arFields = Array(
	  "EMAIL"             => "bitrixoid@mail.ru",
	  "LOGIN"             => "bitrixoid@mail.ru",
	  "LID"               => "ru",
	  "ACTIVE"            => "Y",
	  "GROUP_ID"          => array(1,2),
	  "PASSWORD"          => "bitrixoid@mail.ru",
	  "CONFIRM_PASSWORD"  => "bitrixoid@mail.ru",
	);

	$ID = $user->Add($arFields);
	if (intval($ID) > 0)
		echo "Пользователь ".$login." успешно добавлен.";
	else
		echo $user->LAST_ERROR;	
		
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>