Created
June 23, 2016 07:10
-
-
Save flayder/3670cec8d63623ed00884cd238d84546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php"); | |
CModule::IncludeModule("iblock"); | |
if($_SERVER["REQUEST_METHOD"] == "POST"){ | |
$arResult = array( | |
'errors' => array(), | |
'email' => 'empty' | |
); | |
$metro = trim($_POST['metro']); | |
$login = trim($_POST['login']); | |
$name = trim($_POST['name']); | |
$pass = trim($_POST['password']); | |
$email = trim($_POST['email']); | |
$file = $_FILES['file']; | |
if($_FILES['file']['tmp_name']) { | |
$imgType = array('image/gif', 'image/jpeg', 'image/png'); | |
$types; | |
foreach($imgType as $type) { | |
if($type == $_FILES['file']['type']) { | |
$types = true; | |
} | |
} | |
if($types !== true) { | |
$arResult["errors"][] = "Неверный формат изображения"; | |
} | |
} | |
if(!empty($email)) { | |
if(!preg_match('/[0-9a-z]+[0-9a-z_\.\-]*@[0-9a-z_\-\.]+\.[a-z]{2,6}/i', $email)) { | |
$arResult["errors"][] = "Некорректный email"; | |
} else { | |
$arResult['email'] = "Y"; | |
} | |
} | |
if (strlen($name) < 3) { | |
$arResult["errors"][] = 'Имя должно содержать не меньше 3 символов!'; | |
} | |
if (strlen($login) < 3) { | |
$arResult["errors"][] = 'Логин не должен содержать меньше 3 символов!'; | |
} | |
$rsUsers = CUser::GetList(($by="personal_country"), ($order="desc"), array('LOGIN_EQUAL' => $login), array()); | |
while($rsUsers->NavNext(true, "f_")) : | |
if($f_LOGIN == $login) { | |
$arResult["errors"][] = 'Пользователь с таким логином уже существует!'; | |
} | |
endwhile; | |
unset($rsUsers); | |
if (strlen($pass) < 3) { | |
$arResult["errors"][] = 'Пароль должен содержать не меньше 3 символов!'; | |
} | |
if (empty($arResult['errors']) && $arResult['email'] === "Y") { | |
global $USER; | |
$result = $USER->Register($login, $name, "", $pass, $pass, $email); | |
// foreach ($result as $key => $value) { | |
// $arResult["errors"][] = $key . ' = ' . $value; | |
// } | |
if($result['TYPE'] == 'OK') { | |
if($_FILES['file']['tmp_name']) { | |
$fil = array( | |
'name' => $_FILES['file']['name'], | |
'size' => $_FILES['file']['size'], | |
"tmp_name" => $_FILES['file']['tmp_name'] | |
); | |
$arIMAGE = CFile::MakeFileArray(CFile::GetPath(CFile::SaveFile($fil, 'users/' . $login))); | |
} else { | |
$arIMAGE = CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . '/upload/image-form-ad.jpg'); | |
} | |
$fillter = array( | |
'LOGIN_EQUAL' => $login, | |
"ACTIVE" => "N", | |
'EMAIL' => $email | |
); | |
$fields = array( | |
"GROUP_ID" => array(5), | |
'PERSONAL_PHOTO' => $arIMAGE | |
); | |
$rsUsers = CUser::GetList(($by="personal_country"), ($order="desc"), $fillter, array()); | |
$user = new CUser; | |
while($rsUsers->NavNext(true, "f_")) : | |
$user->Update($f_ID, $fields); | |
endwhile; | |
$arResult["errors"][] = $user->LAST_ERROR; | |
} | |
} | |
echo json_encode($arResult); | |
die(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment