-
Notifications
You must be signed in to change notification settings - Fork 0
Восстановление пароля
atomrus1993 edited this page May 25, 2018
·
3 revisions
function findUserByPhone($phone) {
$user = CUser::GetByLogin($phone);
return $user->Fetch();
}
$phone = preg_replace("/[^0-9]/", null, $_POST['phone']);
$user = findUserByPhone($phone);
$result = null;
$msg = null;
if (strlen($phone) < 11) {
$result = false;
$msg = 'Неправильный номер';
} else {
if ($user) {
$name = $user['NAME'];
$login = $user['LOGIN'];
$email = $user['EMAIL'];
$password = randString(7);
$forgotFields = [
"USER_LOGIN" => $login,
"USER_PASSWORD" => $password,
"USER_EMAIL" => $email,
"USER_NAME" => $name,
];
$passwordUserNew = new CUser;
$passwordUserNew->Update(
$user['ID'],
[
'PASSWORD' => $password,
'CONFIRM_PASSWORD' => $password
]
);
CEvent::Send("FORGOT_PASSWORD", 's1', $forgotFields, "N");
$result = true;
$msg = "Пароль отправлен на ваш e-mail";
} else {
$result = false;
$msg = "Телефон не найден";
}
}
echo json_encode(["result" => $result, "msg" => $msg], JSON_UNESCAPED_UNICODE);