1296 lines
56 KiB
PHP
1296 lines
56 KiB
PHP
<?php
|
||
|
||
class Login
|
||
{
|
||
public static $_sleep = 1;
|
||
|
||
public static $_tpl_dir;
|
||
|
||
public static $_lang_file;
|
||
|
||
public static $_newuser_group = 4;
|
||
|
||
#Регулярное выражение для проверки непечатаемых и нежелательных символов
|
||
public static $_regex = '/[^\x20-\xFF]|[><]/';
|
||
|
||
#Регулярное выражение для проверки даты
|
||
public static $_regex_geb = '#(0[1-9]|[12][0-9]|3[01])([[:punct:]| ])(0[1-9]|1[012])\2(19|20)\d\d#';
|
||
|
||
#Регулярное выражение для проверки e-Mail
|
||
public static $_regex_email = '/^[\w.-]+@[a-z0-9.-]+\.(?:[a-z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)$/i';
|
||
|
||
#Ссылка на страницу после регистрации без проверок
|
||
public static $_reg_now = 'index.php?module=login&action=profile';
|
||
|
||
#Ссылка на страницу после регистрации с проверкой Email
|
||
public static $_reg_email = 'index.php?module=login&action=register&sub=final';
|
||
|
||
#Ссылка на страницу после регистрации с проверкой администратором
|
||
public static $_reg_admin = 'index.php?module=login&action=register&sub=thanks';
|
||
|
||
|
||
/* ---------------------------------------------------------------------------------------------------------------------- */
|
||
/* ---------------------------------------------------------------------------------------------------------------------- */
|
||
/* ---------------------------------------------------------------------------------------------------------------------- */
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _json
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Return array in JSON format
|
||
|
|
||
*/
|
||
public static function _json ($data, $exit = false)
|
||
{
|
||
header('Content-Type: application/json;charset=utf-8');
|
||
|
||
$json = json_encode($data);
|
||
|
||
if ($json === false)
|
||
{
|
||
$json = json_encode(array('jsonError', json_last_error_msg()));
|
||
|
||
if ($json === false)
|
||
{
|
||
$json = '{"jsonError": "unknown"}';
|
||
}
|
||
|
||
http_response_code(500);
|
||
}
|
||
|
||
echo $json;
|
||
|
||
if ($exit)
|
||
exit;
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _required
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Получение параметра "Обязательное поле" для формы авторизации
|
||
|
|
||
| @param string $field название поля БД в котором хранится параметр
|
||
| @return boolean
|
||
|
|
||
*/
|
||
public static function _required ($field)
|
||
{
|
||
return (bool)self::settings($field);
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _requiredfetch
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Передать в Smarty признаки обязательных полей
|
||
|
|
||
*/
|
||
private static function _requiredfetch ()
|
||
{
|
||
global $AVE_Template;
|
||
|
||
if (self::_required('login_require_company'))
|
||
$AVE_Template->assign('company', 1);
|
||
|
||
if (self::_required('login_require_firstname'))
|
||
$AVE_Template->assign('firstname', 1);
|
||
|
||
if (self::_required('login_require_lastname'))
|
||
$AVE_Template->assign('lastname', 1);
|
||
if (self::_required('login_require_country'))
|
||
$AVE_Template->assign('country', 1);
|
||
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _emailexist
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Проверка наличия учетной записи с указанным email
|
||
|
|
||
| @param string $email проверяемый email
|
||
| @return boolean
|
||
|
|
||
*/
|
||
private static function _emailexist ($email)
|
||
{
|
||
global $AVE_DB;
|
||
|
||
$exist = $AVE_DB->Query("
|
||
SELECT 1
|
||
FROM
|
||
" . PREFIX . "_users
|
||
WHERE
|
||
email = '" . $AVE_DB->EscStr($email) . "'
|
||
")->NumRows();
|
||
|
||
return (bool)$exist;
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _nameexists
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Проверка наличия учетной записи с проверяемым именем пользователя
|
||
|
|
||
| @param string $user_name проверяемое имя пользователя
|
||
| @return boolean
|
||
|
|
||
*/
|
||
private static function _nameexists ($user_name)
|
||
{
|
||
global $AVE_DB;
|
||
|
||
$exist = $AVE_DB->Query("
|
||
SELECT 1
|
||
FROM
|
||
" . PREFIX . "_users
|
||
WHERE
|
||
user_name = '" . $AVE_DB->EscStr($user_name) . "'
|
||
LIMIT 1
|
||
")->NumRows();
|
||
|
||
return (bool)$exist;
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _blacklist
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Проверка наличия в черном списке email
|
||
|
|
||
| @param string $email
|
||
| @return boolean
|
||
|
|
||
*/
|
||
private static function _blacklist ($email)
|
||
{
|
||
if (empty($email))
|
||
return false;
|
||
|
||
$deny_emails = explode(',', chop(self::settings('login_deny_email')));
|
||
|
||
return ! in_array($email, $deny_emails);
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| _domaincheck
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Проверка наличия в черном списке доменного имени
|
||
|
|
||
| @param string $email email доменное имя которого надо проверить
|
||
| @return boolean
|
||
|
|
||
*/
|
||
private static function _domaincheck ($email = '')
|
||
{
|
||
if (empty($email))
|
||
return false;
|
||
|
||
$deny_domains = explode(',', chop(self::settings('login_deny_domain')));
|
||
$domain = explode('@', $email);
|
||
|
||
return ! in_array(@$domain[1], $deny_domains);
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| settings
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function settings ($field = '')
|
||
{
|
||
global $AVE_DB;
|
||
|
||
static $settings = null;
|
||
|
||
if ($settings === null)
|
||
{
|
||
$sql = "
|
||
SELECT
|
||
*
|
||
FROM
|
||
" . PREFIX . "_module_login
|
||
WHERE
|
||
id = '1'
|
||
";
|
||
|
||
$res = $AVE_DB->Query($sql, -1, 'modules/login', true, '.settings');
|
||
|
||
// В PHP 8.4 проверяем, что $res — это объект, прежде чем дергать метод
|
||
$settings = (is_object($res)) ? $res->FetchAssocArray() : array();
|
||
}
|
||
|
||
if ($field == '')
|
||
return $settings;
|
||
|
||
// Используем Null Coalescing Operator для защиты от Notice в PHP 8.4
|
||
return $settings[$field] ?? null;
|
||
}
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| getlinks
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Получение параметра настройки модуля Авторизация
|
||
|
|
||
*/
|
||
public static function getlinks ()
|
||
{
|
||
global $AVE_DB;
|
||
|
||
static $links = [];
|
||
|
||
if (empty($links))
|
||
{
|
||
$sql = $AVE_DB->Query("
|
||
SELECT
|
||
module_action,
|
||
module_url
|
||
FROM
|
||
" . PREFIX . "_module_urls
|
||
WHERE
|
||
module_name = 'login'
|
||
");
|
||
|
||
while($row = $sql->FetchAssocArray())
|
||
$links[$row['module_action']] = $row['module_url'];
|
||
}
|
||
|
||
return $links;
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| form
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function form ()
|
||
{
|
||
global $AVE_Template;
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'loginform');
|
||
|
||
if (self::settings('login_status') == 1)
|
||
$AVE_Template->assign('active', 1);
|
||
|
||
// PHP 8.4: Принудительно приводим к строке (string), чтобы избежать
|
||
// ошибки Deprecated/Fatal при передаче null в системные функции шаблонизатора.
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_AUTORIZATION'));
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'loginform.tpl'));
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| authorize
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function authorize ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
if (empty($_SESSION['referer']))
|
||
{
|
||
$referer = get_referer_link();
|
||
|
||
// Проверяем наличие referer, исключая саму страницу логина
|
||
$_SESSION['referer'] = (false === strstr((string)$referer, 'module=login'))
|
||
? $referer
|
||
: get_home_link();
|
||
}
|
||
|
||
// PHP 8.4: гарантируем тип string для входящих данных из POST
|
||
$login = addslashes((string)($_POST['user_login'] ?? ''));
|
||
$password = (string)($_POST['user_pass'] ?? '');
|
||
|
||
$keep_in = isset($_POST['keep_in'])
|
||
? (int)$_POST['keep_in']
|
||
: false;
|
||
|
||
if ($login !== '' && $password !== '')
|
||
{
|
||
// Вызов системной функции авторизации ядра AVE.cms
|
||
$result = user_login($login, $password, 1, $keep_in);
|
||
|
||
if ($result === true)
|
||
{
|
||
// Успешный вход: редирект на сохраненный referer
|
||
$target = $_SESSION['referer'] ?? get_home_link();
|
||
header('Location:' . rewrite_link((string)$target));
|
||
unset($_SESSION['referer']);
|
||
exit;
|
||
}
|
||
elseif ($result === 3)
|
||
{
|
||
// Случай, когда требуется активация (статус 3)
|
||
header('Location:' . ABS_PATH . 'index.php?module=login&action=register&sub=final');
|
||
exit;
|
||
}
|
||
else
|
||
{
|
||
// Ошибка входа: чистим сессию
|
||
unset($_SESSION['user_id'], $_SESSION['user_pass']);
|
||
$AVE_Template->assign('login', false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$AVE_Template->assign('login', false);
|
||
}
|
||
|
||
if (self::settings('login_status') == 1)
|
||
$AVE_Template->assign('active', 1);
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'loginprocess');
|
||
|
||
if (! defined('MODULE_CONTENT'))
|
||
{
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_AUTORIZATION'));
|
||
}
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'process.tpl'));
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| logout
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function logout ()
|
||
{
|
||
// Вызываем системную функцию ядра для очистки куки и сессий
|
||
user_logout();
|
||
|
||
// Получаем адрес страницы, с которой пришел пользователь
|
||
$referer_link = get_referer_link();
|
||
|
||
// PHP 8.4: Приводим к строке, чтобы strstr не ругался на null.
|
||
// Если мы выходим со страницы логина, кидаем на главную,
|
||
// чтобы не зацикливать форму.
|
||
if (false === strstr((string)$referer_link, 'module=login'))
|
||
{
|
||
header('Location:' . $referer_link);
|
||
}
|
||
else
|
||
{
|
||
header('Location:' . get_home_link());
|
||
}
|
||
exit;
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| profile
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function profile ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
if (! isset($_SESSION['user_id']) || ! isset($_SESSION['user_pass']))
|
||
{
|
||
header('Location:' . get_home_link());
|
||
exit;
|
||
}
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'myprofile');
|
||
|
||
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'update')
|
||
{
|
||
$errors = array();
|
||
|
||
if (self::_required('login_require_firstname') && empty($_POST['firstname']))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_FN_EMPTY');
|
||
|
||
if (preg_match(self::$_regex, (string)($_POST['firstname'] ?? '')))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_FIRSTNAME');
|
||
|
||
if (self::_required('login_require_lastname') && empty($_POST['lastname']))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_LN_EMPTY');
|
||
|
||
if (preg_match(self::$_regex, (string)($_POST['lastname'] ?? '')))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_LASTNAME');
|
||
|
||
if (! empty($_POST['street']) && preg_match(self::$_regex, (string)$_POST['street']))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_STREET');
|
||
|
||
if (! empty($_POST['street_nr']) && preg_match(self::$_regex, (string)$_POST['street_nr']))
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_HOUSE');
|
||
|
||
if (! preg_match(self::$_regex_email, (string)($_POST['email'] ?? '')))
|
||
{
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_EMAIL');
|
||
}
|
||
else
|
||
{
|
||
$exist = $AVE_DB->Query("
|
||
SELECT 1 FROM " . PREFIX . "_users
|
||
WHERE Id != '" . (int)$_SESSION['user_id'] . "'
|
||
AND email = '" . addslashes((string)$_POST['email']) . "'
|
||
")->NumRows();
|
||
|
||
if ($exist)
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_INUSE');
|
||
}
|
||
|
||
if (! empty($errors))
|
||
{
|
||
$AVE_Template->assign('errors', $errors);
|
||
}
|
||
else
|
||
{
|
||
// --- ОБРАБОТКА АВАТАРА ---
|
||
$avatar_dir = str_replace('\\', '/', realpath(BASE_DIR . '/' . UPLOAD_DIR . '/avatars')) . '/';
|
||
|
||
// Получаем текущий хеш из Email и хеш из системы (getAvatar)
|
||
$u_data = $AVE_DB->Query("SELECT email FROM " . PREFIX . "_users WHERE Id = '" . (int)$_SESSION['user_id'] . "'")->FetchAssocArray();
|
||
$email_hash = md5(strtolower(trim((string)$u_data['email'])));
|
||
|
||
$sys_avatar_url = getAvatar((int)$_SESSION['user_id']);
|
||
$raw_name = basename(parse_url((string)$sys_avatar_url, PHP_URL_PATH));
|
||
$sys_hash = (!empty($raw_name)) ? substr($raw_name, 0, 32) : '';
|
||
|
||
// Универсальный чистильщик
|
||
$cleaner = function($dir, $search_hash) {
|
||
if (strlen((string)$search_hash) < 10 || !is_dir($dir)) return;
|
||
clearstatcache();
|
||
$it = new RecursiveIteratorIterator(
|
||
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
|
||
RecursiveIteratorIterator::CHILD_FIRST
|
||
);
|
||
foreach ($it as $f) {
|
||
if (strpos($f->getFilename(), (string)$search_hash) !== false) {
|
||
$p = $f->getRealPath();
|
||
@chmod($p, 0666);
|
||
@unlink($p);
|
||
}
|
||
}
|
||
};
|
||
|
||
// УДАЛЕНИЕ
|
||
if (!empty($_POST['delete_avatar'])) {
|
||
if (!empty($sys_hash)) $cleaner($avatar_dir, $sys_hash);
|
||
if (!empty($email_hash) && $email_hash !== $sys_hash) $cleaner($avatar_dir, $email_hash);
|
||
|
||
if (function_exists('SetAvatar')) SetAvatar((int)$_SESSION['user_id'], '');
|
||
|
||
header('Location: index.php?module=login&action=info&save=ok');
|
||
exit;
|
||
}
|
||
|
||
// ЗАГРУЗКА
|
||
if (isset($_FILES['avatar']) && $_FILES['avatar']['error'] == UPLOAD_ERR_OK) {
|
||
// Сносим старье перед загрузкой
|
||
if (!empty($sys_hash)) $cleaner($avatar_dir, $sys_hash);
|
||
if (!empty($email_hash)) $cleaner($avatar_dir, $email_hash);
|
||
|
||
$tmp = $_FILES['avatar']['tmp_name'];
|
||
$ext = pathinfo($_FILES['avatar']['name'], PATHINFO_EXTENSION);
|
||
$final_path = $avatar_dir . $email_hash . '.' . $ext;
|
||
|
||
if (move_uploaded_file($tmp, $final_path)) {
|
||
if (function_exists('SetAvatar')) SetAvatar((int)$_SESSION['user_id'], $final_path);
|
||
}
|
||
}
|
||
// --- КОНЕЦ БЛОКА АВАТАРА ---
|
||
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_users
|
||
SET
|
||
firstname = '" . addslashes((string)$_POST['firstname']) . "',
|
||
lastname = '" . addslashes((string)$_POST['lastname']) . "',
|
||
email = '" . addslashes((string)$_POST['email']) . "',
|
||
street = '" . addslashes((string)($_POST['street'] ?? '')) . "',
|
||
street_nr = '" . addslashes((string)($_POST['street_nr'] ?? '')) . "',
|
||
zipcode = '" . addslashes((string)($_POST['zipcode'] ?? '')) . "',
|
||
city = '" . addslashes((string)($_POST['city'] ?? '')) . "',
|
||
phone = '" . addslashes((string)($_POST['phone'] ?? '')) . "',
|
||
country = '" . addslashes((string)($_POST['country'] ?? '')) . "',
|
||
birthday = '" . addslashes((string)($_POST['birthday'] ?? '')) . "',
|
||
company = '" . addslashes((string)($_POST['company'] ?? '')) . "'
|
||
WHERE
|
||
Id = '" . (int)$_SESSION['user_id'] . "'
|
||
AND
|
||
password = '" . addslashes((string)$_SESSION['user_pass']) . "'
|
||
");
|
||
|
||
header('Location: index.php?module=login&action=info&save=ok');
|
||
exit;
|
||
}
|
||
}
|
||
|
||
$sql = "SELECT * FROM " . PREFIX . "_users WHERE Id = '" . (int)$_SESSION['user_id'] . "' LIMIT 1";
|
||
$user = $AVE_DB->Query($sql)->FetchAssocArray();
|
||
|
||
// --- ВЫВОД АВАТАРА ---
|
||
$u_avatar = getAvatar((int)$_SESSION['user_id'], 150);
|
||
|
||
// Берем ABS_PATH из константы или переменной Smarty
|
||
$abs_path = (defined('ABS_PATH')) ? ABS_PATH : '/';
|
||
|
||
// Если аватар пустой или это старая заглушка (маленькая 40х40)
|
||
if (empty($u_avatar) || strpos($u_avatar, 'user.png') !== false) {
|
||
$u_avatar = $abs_path . 'uploads/avatars/default.png';
|
||
}
|
||
|
||
$AVE_Template->assign('user_avatar', $u_avatar);
|
||
// ---------------------------------
|
||
|
||
$AVE_Template->assign('available_countries', get_country_list(1));
|
||
$AVE_Template->assign('row', $user);
|
||
|
||
self::_requiredfetch();
|
||
|
||
if (!defined('MODULE_TITLE')) define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_CHANGE_DETAILS'));
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'profile.tpl'));
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| info
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function info ()
|
||
{
|
||
global $AVE_Template;
|
||
|
||
$user_id = (int)($_SESSION['user_id'] ?? 0);
|
||
|
||
// Получаем запись пользователя.
|
||
$userinfo = get_user_rec_by_id($user_id);
|
||
|
||
if (!$userinfo) return;
|
||
|
||
$u_avatar = getAvatar($user_id, 150); // Увеличил размер до 150 для четкости
|
||
$abs_path = (defined('ABS_PATH')) ? ABS_PATH : '/';
|
||
|
||
// Если аватар пустой или содержит заглушку
|
||
if (empty($u_avatar) || strpos($u_avatar, 'user.png') !== false) {
|
||
$u_avatar = $abs_path . 'uploads/avatars/default.png';
|
||
}
|
||
|
||
$userinfo->avatar = $u_avatar;
|
||
|
||
$AVE_Template->assign('user', $userinfo);
|
||
$AVE_Template->config_load(self::$_lang_file, 'userinfo');
|
||
|
||
if (! defined('MODULE_CONTENT'))
|
||
{
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_USER_PROFILE'));
|
||
}
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'info.tpl'));
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| profile
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Управление модулем Авторизации
|
||
|
|
||
*/
|
||
public static function admin ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'save')
|
||
{
|
||
// PHP 8.4: гарантируем, что входящие списки — это строки
|
||
$login_deny_domain = str_replace(array("\r\n", "\n"), ',', (string)($_REQUEST['login_deny_domain'] ?? ''));
|
||
$login_deny_email = str_replace(array("\r\n", "\n"), ',', (string)($_REQUEST['login_deny_email'] ?? ''));
|
||
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_module_login
|
||
SET
|
||
login_reg_type = '" . addslashes((string)($_REQUEST['login_reg_type'] ?? '')) . "',
|
||
login_antispam = '" . addslashes((string)($_REQUEST['login_antispam'] ?? '0')) . "',
|
||
login_status = '" . addslashes((string)($_REQUEST['login_status'] ?? '0')) . "',
|
||
login_deny_domain = '" . addslashes($login_deny_domain) . "',
|
||
login_deny_email = '" . addslashes($login_deny_email) . "',
|
||
login_require_company = '" . addslashes((string)($_REQUEST['login_require_company'] ?? '0')) . "',
|
||
login_require_firstname = '" . addslashes((string)($_REQUEST['login_require_firstname'] ?? '0')) . "',
|
||
login_require_lastname = '" . addslashes((string)($_REQUEST['login_require_lastname'] ?? '0')) . "',
|
||
login_require_country = '" . addslashes((string)($_REQUEST['login_require_country'] ?? '0')) . "'
|
||
WHERE Id = 1
|
||
");
|
||
|
||
$AVE_DB->clearCache('modules/login');
|
||
|
||
// Используем встроенную функцию ядра для проверки Ajax запроса
|
||
if (isAjax()) {
|
||
exit("success");
|
||
}
|
||
|
||
header('Location:index.php?do=modules&action=modedit&mod=login&moduleaction=1&cp=' . SESSION);
|
||
exit;
|
||
}
|
||
|
||
$row = self::settings();
|
||
// Обратное преобразование запятых в переносы строк для текстового поля
|
||
$row['login_deny_domain'] = str_replace(',', "\n", (string)($row['login_deny_domain'] ?? ''));
|
||
$row['login_deny_email'] = str_replace(',', "\n", (string)($row['login_deny_email'] ?? ''));
|
||
|
||
$AVE_Template->assign($row);
|
||
$AVE_Template->assign('content', $AVE_Template->fetch(self::$_tpl_dir . 'config.tpl'));
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| reminder
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function reminder ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
// Если пользователь уже вошел, восстановление ему не нужно
|
||
if (isset($_SESSION['user_id']))
|
||
{
|
||
header('Location:' . get_home_link());
|
||
exit;
|
||
}
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'passwordreminder');
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_REMIND'));
|
||
}
|
||
|
||
// ФАЗА 2: Подтверждение сброса (переход по ссылке из письма)
|
||
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'confirm' && !empty($_REQUEST['email']))
|
||
{
|
||
// Ищем пользователя, у которого совпадает email и временный код (new_pass)
|
||
$row_remind = $AVE_DB->Query("
|
||
SELECT new_pass, new_salt
|
||
FROM " . PREFIX . "_users
|
||
WHERE email = '" . addslashes((string)$_REQUEST['email']) . "'
|
||
AND new_pass != ''
|
||
AND new_pass = '" . addslashes((string)($_REQUEST['code'] ?? '')) . "'
|
||
LIMIT 1
|
||
")->FetchRow();
|
||
|
||
if ($row_remind)
|
||
{
|
||
// Переносим временный пароль в основной и очищаем временные поля
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_users
|
||
SET
|
||
password = '" . addslashes((string)$row_remind->new_pass) . "',
|
||
salt = '" . addslashes((string)$row_remind->new_salt) . "',
|
||
new_pass = '',
|
||
new_salt = ''
|
||
WHERE email = '" . addslashes((string)$_REQUEST['email']) . "'
|
||
");
|
||
$AVE_Template->assign('remind_ok', 1);
|
||
}
|
||
else
|
||
{
|
||
$AVE_Template->assign('remind_error', 1);
|
||
}
|
||
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'reminder_end.tpl'));
|
||
}
|
||
// ФАЗА 1: Запрос на восстановление (ввод email в форму)
|
||
else
|
||
{
|
||
if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'send' && !empty($_POST['f_mailreminder']))
|
||
{
|
||
$email_input = (string)$_POST['f_mailreminder'];
|
||
|
||
$row_remind = $AVE_DB->Query("
|
||
SELECT email, user_name, firstname, lastname
|
||
FROM " . PREFIX . "_users
|
||
WHERE email = '" . addslashes($email_input) . "'
|
||
LIMIT 1
|
||
")->FetchRow();
|
||
|
||
if ($row_remind)
|
||
{
|
||
// Генерируем новый случайный пароль и соль
|
||
$newpass_plain = make_random_string(8, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789");
|
||
$newsalt = make_random_string();
|
||
$md5_pass_salt = md5(md5($newpass_plain . $newsalt));
|
||
|
||
// Записываем временные данные в поля new_pass и new_salt
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_users
|
||
SET
|
||
new_pass = '" . addslashes($md5_pass_salt) . "',
|
||
new_salt = '" . addslashes($newsalt) . "'
|
||
WHERE email = '" . addslashes($email_input) . "'
|
||
");
|
||
|
||
// Формируем письмо
|
||
$link = get_home_link() . "index.php?module=login&action=reminder&sub=confirm&email=" . urlencode($email_input) . "&code=" . $md5_pass_salt;
|
||
|
||
// Получаем текст шаблона из конфига
|
||
$body = (string)$AVE_Template->get_config_vars('LOGIN_MESSAGE_6');
|
||
|
||
// Заменяем переменные
|
||
$body = str_replace("%NAME%", (string)$row_remind->user_name, $body);
|
||
$body = str_replace("%HOST%", $_SERVER['HTTP_HOST'], $body);
|
||
$body = str_replace("%PASS%", $newpass_plain, $body);
|
||
$body = str_replace("%LINK%", $link, $body);
|
||
$body = str_replace("%N%", "\n", $body);
|
||
|
||
send_mail(
|
||
$row_remind->email,
|
||
$body,
|
||
(string)$AVE_Template->get_config_vars('LOGIN_SUBJECT_REMINDER'),
|
||
get_settings('mail_from'),
|
||
get_settings('mail_from_name'),
|
||
'text'
|
||
);
|
||
|
||
$AVE_Template->assign('send_success', 1);
|
||
}
|
||
else
|
||
{
|
||
$AVE_Template->assign('send_error', 1);
|
||
}
|
||
}
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'reminder.tpl'));
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| change
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function change ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'passwordchange');
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_PASSWORD_CHANGE'));
|
||
}
|
||
|
||
// Если пользователь не авторизован, ему здесь делать нечего
|
||
if (! isset($_SESSION['user_id']))
|
||
{
|
||
header('Location:' . get_home_link());
|
||
exit;
|
||
}
|
||
|
||
// Получаем соль текущего пользователя для проверки старого пароля
|
||
$salt = $AVE_DB->Query("
|
||
SELECT salt
|
||
FROM " . PREFIX . "_users
|
||
WHERE Id = '" . (int)$_SESSION['user_id'] . "'
|
||
LIMIT 1
|
||
")->GetCell();
|
||
|
||
// Обработка формы смены пароля
|
||
if ($salt !== false && isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'send')
|
||
{
|
||
$error = array();
|
||
|
||
// PHP 8.4: Безопасное получение данных из POST
|
||
$old_pass = (string)($_POST['old_pass'] ?? '');
|
||
$new_pass = (string)($_POST['new_pass'] ?? '');
|
||
|
||
// Проверка старого пароля
|
||
if ($old_pass === '')
|
||
{
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_EMPTY_OLD_PASS');
|
||
}
|
||
// Сверяем MD5-хеш старого пароля с тем, что хранится в сессии
|
||
elseif ($_SESSION['user_pass'] != md5(md5($old_pass . $salt)))
|
||
{
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_OLD_PASS');
|
||
}
|
||
|
||
// Проверка нового пароля
|
||
if ($new_pass === '')
|
||
{
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_EMPTY_NEW_PASS');
|
||
}
|
||
|
||
if (count($error) == 0)
|
||
{
|
||
// Генерируем новую соль и новый хеш для безопасности
|
||
$newsalt = make_random_string();
|
||
$md5_pass_salt = md5(md5($new_pass . $newsalt));
|
||
|
||
// Обновляем данные в БД
|
||
$AVE_DB->Query("
|
||
UPDATE " . PREFIX . "_users
|
||
SET
|
||
password = '" . addslashes($md5_pass_salt) . "',
|
||
salt = '" . addslashes($newsalt) . "'
|
||
WHERE Id = '" . (int)$_SESSION['user_id'] . "'
|
||
");
|
||
|
||
// Обновляем пароль в текущей сессии, чтобы пользователя не "выкинуло"
|
||
$_SESSION['user_pass'] = $md5_pass_salt;
|
||
|
||
$AVE_Template->assign('changeok', 1);
|
||
}
|
||
else
|
||
{
|
||
$AVE_Template->assign('errors', $error);
|
||
}
|
||
}
|
||
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'change.tpl'));
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| delete
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function delete ()
|
||
{
|
||
global $AVE_Template;
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'delaccount');
|
||
|
||
// Если пользователь не авторизован — на выход
|
||
if (! isset($_SESSION['user_id']))
|
||
{
|
||
header('Location: index.php?id=1');
|
||
exit;
|
||
}
|
||
|
||
// Проверяем подтверждение удаления (обычно это чекбокс в форме)
|
||
// и следим, чтобы это не был Главный администратор (UGROUP != 1)
|
||
if (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 1 && UGROUP != 1)
|
||
{
|
||
// Вызываем функцию ядра для удаления
|
||
user_delete((int)$_SESSION['user_id']);
|
||
|
||
// Очищаем сессию, так как пользователя больше не существует
|
||
unset($_SESSION['user_id'], $_SESSION['user_pass']);
|
||
|
||
$AVE_Template->assign('delok', 1);
|
||
}
|
||
// Если попытка удалить админа
|
||
elseif (isset($_REQUEST['confirm']) && UGROUP == 1)
|
||
{
|
||
$AVE_Template->assign('is_admin', 1);
|
||
}
|
||
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_DELETE_ACCOUNT'));
|
||
}
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'delete.tpl'));
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| register
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
| Регистрация новой учетной записи пользователя
|
||
|
|
||
*/
|
||
public static function register ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
|
||
if (isset($_SESSION['user_id']) || isset($_SESSION['user_pass']))
|
||
{
|
||
header('Location:' . get_referer_link());
|
||
exit;
|
||
}
|
||
|
||
if (empty($_SESSION['referer']))
|
||
{
|
||
$referer = get_referer_link();
|
||
$_SESSION['referer'] = (false === strstr((string)$referer, 'module=login')) ? $referer : get_home_link();
|
||
}
|
||
|
||
$AVE_Template->config_load(self::$_lang_file, 'registernew');
|
||
|
||
if (!defined('MODULE_TITLE'))
|
||
{
|
||
define('MODULE_TITLE', (string)$AVE_Template->get_config_vars('LOGIN_TEXT_REGISTER'));
|
||
}
|
||
|
||
if (self::settings('login_antispam'))
|
||
define('ANTISPAM', 1);
|
||
|
||
switch(self::settings('login_status'))
|
||
{
|
||
case '1':
|
||
$sub = (string)($_REQUEST['sub'] ?? '');
|
||
switch ($sub)
|
||
{
|
||
case 'register':
|
||
$error = [];
|
||
|
||
$_POST['user_name'] = (! empty($_POST['user_name']))
|
||
? trim((string)$_POST['user_name'])
|
||
: '';
|
||
|
||
$_POST['reg_email'] = (! empty($_POST['reg_email']))
|
||
? trim((string)$_POST['reg_email'])
|
||
: '';
|
||
|
||
$_POST['reg_email_return'] = (! empty($_POST['reg_email_return']))
|
||
? trim((string)$_POST['reg_email_return'])
|
||
: '';
|
||
|
||
// user_name
|
||
$regex_username = '/[^\w-]/';
|
||
|
||
if (empty($_POST['user_name']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_L_EMPTY');
|
||
elseif (preg_match($regex_username, (string)$_POST['user_name']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_LOGIN');
|
||
elseif (self::_nameexists($_POST['user_name']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_L_INUSE');
|
||
|
||
// reg_email
|
||
if (empty($_POST['reg_email']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_EM_EMPTY');
|
||
elseif (! preg_match(self::$_regex_email, (string)$_POST['reg_email']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_EMAIL');
|
||
else
|
||
{
|
||
if (self::_emailexist($_POST['reg_email']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_INUSE');
|
||
if (! self::_domaincheck($_POST['reg_email']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_DOMAIN_FALSE');
|
||
if (! self::_blacklist($_POST['reg_email']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_EMAIL_FALSE');
|
||
}
|
||
|
||
// reg_pass
|
||
if (empty($_POST['reg_pass']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_PASS');
|
||
elseif (mb_strlen((string)$_POST['reg_pass']) < 5)
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_SHORT_PASS');
|
||
elseif (preg_match(self::$_regex, (string)$_POST['reg_pass']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_SYM_PASS');
|
||
|
||
// reg_firstname
|
||
if (self::_required('login_require_firstname') && empty($_POST['reg_firstname']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_FN_EMPTY');
|
||
if (!empty($_POST['reg_firstname']) && preg_match(self::$_regex, (string)$_POST['reg_firstname']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_FIRSTNAME');
|
||
|
||
// reg_lastname
|
||
if (self::_required('login_require_lastname') && empty($_POST['reg_lastname']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_LN_EMPTY');
|
||
if (! empty($_POST['reg_lastname']) && preg_match(self::$_regex, (string)$_POST['reg_lastname']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_LASTNAME');
|
||
// Проверка страны (если включено в админке и не выбрано)
|
||
if (self::_required('login_require_country') && empty($_POST['country'])) {
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WRONG_COUNTRY_EMPTY');
|
||
}
|
||
|
||
if (defined("ANTISPAM"))
|
||
{
|
||
$reg_secure = (string)($_POST['reg_secure'] ?? '');
|
||
if (empty($reg_secure))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WROND_E_SCODE');
|
||
elseif (! (isset($_SESSION['captcha_keystring']) && $reg_secure == $_SESSION['captcha_keystring']))
|
||
$error[] = $AVE_Template->get_config_vars('LOGIN_WROND_SCODE');
|
||
|
||
unset($_SESSION['captcha_keystring']);
|
||
}
|
||
|
||
if (count($error))
|
||
{
|
||
$AVE_Template->assign('errors', $error);
|
||
|
||
if (defined('ANTISPAM'))
|
||
$AVE_Template->assign('im', 1);
|
||
|
||
self::_requiredfetch();
|
||
|
||
$AVE_Template->assign('available_countries', get_country_list(1));
|
||
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'register.tpl'));
|
||
}
|
||
else
|
||
{
|
||
$status = 0;
|
||
$emailcode = md5((string)rand(100000,999999));
|
||
$log_reg_type = self::settings('login_reg_type');
|
||
|
||
switch ($log_reg_type)
|
||
{
|
||
case 'now':
|
||
$email_body = str_replace("%N%", "\n", (string)$AVE_Template->get_config_vars('LOGIN_MESSAGE_1'));
|
||
$email_body = str_replace("%NAME%", (string)$_POST['user_name'], $email_body);
|
||
$email_body = str_replace("%HOST%", get_home_link(), $email_body);
|
||
$email_body = str_replace("%PASSWORD%", (string)$_POST['reg_pass'], $email_body);
|
||
$email_body = str_replace("%EMAIL%", (string)$_POST['reg_email'], $email_body);
|
||
$status = 1;
|
||
$link = self::$_reg_now;
|
||
break;
|
||
|
||
case 'email':
|
||
$email_body = str_replace("%N%", "\n", (string)$AVE_Template->get_config_vars('LOGIN_MESSAGE_2')
|
||
. $AVE_Template->get_config_vars('LOGIN_MESSAGE_3'));
|
||
$email_body = str_replace("%NAME%", (string)$_POST['user_name'], $email_body);
|
||
$email_body = str_replace("%PASSWORD%", (string)$_POST['reg_pass'], $email_body);
|
||
$email_body = str_replace("%EMAIL%", (string)$_POST['reg_email'], $email_body);
|
||
$email_body = str_replace("%REGLINK%",
|
||
get_home_link() . "index.php"
|
||
. "?module=login"
|
||
. "&action=register"
|
||
. "&sub=final"
|
||
. "&emc=" . $emailcode,
|
||
$email_body);
|
||
$email_body = str_replace("%HOST%", get_home_link(), $email_body);
|
||
$email_body = str_replace("%CODE%", $emailcode, $email_body);
|
||
$link = self::$_reg_email;
|
||
break;
|
||
|
||
case 'byadmin':
|
||
$email_body = str_replace("%N%", "\n", (string)$AVE_Template->get_config_vars('LOGIN_MESSAGE_2')
|
||
. $AVE_Template->get_config_vars('LOGIN_MESSAGE_4'));
|
||
$email_body = str_replace("%NAME%", (string)$_POST['user_name'], $email_body);
|
||
$email_body = str_replace("%PASSWORD%", (string)$_POST['reg_pass'], $email_body);
|
||
$email_body = str_replace("%EMAIL%", (string)$_POST['reg_email'], $email_body);
|
||
$email_body = str_replace("%HOST%", get_home_link(), $email_body);
|
||
$link = self::$_reg_admin;
|
||
break;
|
||
}
|
||
|
||
$bodytoadmin = str_replace("%N%", "\n", (string)$AVE_Template->get_config_vars('LOGIN_MESSAGE_5'));
|
||
$bodytoadmin = str_replace("%NAME%", (string)$_POST['user_name'], $bodytoadmin);
|
||
$bodytoadmin = str_replace("%EMAIL%", (string)$_POST['reg_email'], $bodytoadmin);
|
||
|
||
$salt = make_random_string();
|
||
$md5_pass_salt = md5(md5((string)$_POST['reg_pass'] . $salt));
|
||
|
||
$q = "
|
||
INSERT INTO
|
||
" . PREFIX . "_users
|
||
SET
|
||
Id = '',
|
||
user_name = '" . addslashes((string)$_POST['user_name']) . "',
|
||
password = '" . addslashes($md5_pass_salt) . "',
|
||
firstname = '" . addslashes((string)$_POST['reg_firstname']) . "',
|
||
lastname = '" . addslashes((string)$_POST['reg_lastname']) . "',
|
||
user_group = '" . (int)self::$_newuser_group . "',
|
||
reg_time = '" . time() . "',
|
||
status = '" . $status . "',
|
||
email = '" . addslashes((string)$_POST['reg_email']) . "',
|
||
emc = '" . addslashes($emailcode) . "',
|
||
country = '" . addslashes(strtoupper((string)($_POST['country'] ?? ''))) . "',
|
||
reg_ip = '" . addslashes((string)$_SERVER['REMOTE_ADDR']) . "',
|
||
taxpay = '1',
|
||
company = '" . addslashes((string)($_POST['company'] ?? '')) . "',
|
||
salt = '" . addslashes($salt) . "'
|
||
";
|
||
|
||
$AVE_DB->Query($q);
|
||
|
||
if ($status == 1)
|
||
{
|
||
$_SESSION['user_id'] = $AVE_DB->InsertId();
|
||
$_SESSION['user_name'] = get_username(
|
||
stripslashes((string)$_POST['user_name']),
|
||
stripslashes((string)$_POST['reg_firstname']),
|
||
stripslashes((string)$_POST['reg_lastname'])
|
||
);
|
||
$_SESSION['user_email'] = $_POST['reg_email'];
|
||
$_SESSION['user_pass'] = $md5_pass_salt;
|
||
$_SESSION['user_group'] = self::$_newuser_group;
|
||
$_SESSION['user_country'] = strtoupper((string)($_POST['country'] ?? ''));
|
||
$_SESSION['user_ip'] = addslashes((string)$_SERVER['REMOTE_ADDR']);
|
||
|
||
$user_group_permissions = $AVE_DB->Query("SELECT user_group_permission FROM ".PREFIX."_user_groups WHERE user_group=". (int)self::$_newuser_group)->GetCell();
|
||
$user_group_permissions = explode('|', preg_replace('/\s+/', '', (string)$user_group_permissions));
|
||
|
||
foreach ($user_group_permissions as $user_group_permission)
|
||
if ($user_group_permission !== '') $_SESSION[$user_group_permission] = 1;
|
||
}
|
||
|
||
$SystemMail = get_settings('mail_from');
|
||
$SystemMailName = get_settings('mail_from_name');
|
||
|
||
send_mail($SystemMail, $bodytoadmin, (string)$AVE_Template->get_config_vars('LOGIN_SUBJECT_ADMIN'), $SystemMail, $SystemMailName, 'text');
|
||
|
||
if (($_SESSION['loginza_auth'] ?? 0) != 1)
|
||
send_mail($_POST['reg_email'], $email_body, (string)$AVE_Template->get_config_vars('LOGIN_SUBJECT_USER'), $SystemMail, $SystemMailName, 'text');
|
||
|
||
header('Location:' . $link);
|
||
exit;
|
||
}
|
||
break;
|
||
|
||
case 'thanks':
|
||
$AVE_Template->config_load(self::$_lang_file);
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'register_thankyou.tpl'));
|
||
break;
|
||
|
||
case 'final':
|
||
if (isset($_REQUEST['emc']) && $_REQUEST['emc'] != '')
|
||
{
|
||
$row = $AVE_DB->Query("SELECT * FROM " . PREFIX . "_users WHERE emc = '" . addslashes((string)$_REQUEST['emc']) . "'")->FetchRow();
|
||
if ($row)
|
||
{
|
||
$AVE_Template->assign('final', 'ok');
|
||
$AVE_DB->Query("UPDATE " . PREFIX . "_users SET status = '1' WHERE emc = '" . addslashes((string)$_REQUEST['emc']) . "'");
|
||
|
||
// Авто-логин после активации
|
||
$_SESSION['user_id'] = $row->Id;
|
||
$_SESSION['user_name'] = get_username($row->user_name, $row->firstname, $row->lastname);
|
||
$_SESSION['user_email'] = $row->email;
|
||
$_SESSION['user_pass'] = $row->password;
|
||
$_SESSION['user_group'] = $row->user_group;
|
||
$_SESSION['user_country'] = $row->country;
|
||
$_SESSION['user_ip'] = addslashes((string)$_SERVER['REMOTE_ADDR']);
|
||
|
||
$user_group_permissions = $AVE_DB->Query("SELECT user_group_permission FROM ".PREFIX."_user_groups WHERE user_group=". (int)$row->user_group)->GetCell();
|
||
$user_group_permissions = explode('|', preg_replace('/\s+/', '', (string)$user_group_permissions));
|
||
foreach ($user_group_permissions as $user_group_permission)
|
||
if ($user_group_permission !== '') $_SESSION[$user_group_permission] = 1;
|
||
}
|
||
}
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'register_final.tpl'));
|
||
break;
|
||
|
||
case 'admin':
|
||
$AVE_Template->config_load(self::$_lang_file);
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'register_admin.tpl'));
|
||
break;
|
||
|
||
case '':
|
||
default :
|
||
if (defined('ANTISPAM'))
|
||
$AVE_Template->assign('im', 1);
|
||
self::_requiredfetch();
|
||
$AVE_Template->assign('available_countries', get_country_list(1));
|
||
define('MODULE_CONTENT', $AVE_Template->fetch(self::$_tpl_dir . 'register.tpl'));
|
||
break;
|
||
}
|
||
break;
|
||
|
||
case '0':
|
||
define('MODULE_CONTENT', (string)$AVE_Template->get_config_vars('LOGIN_NOT_ACTIVE'));
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| checkusername
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function checkusername ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
$AVE_Template->config_load(self::$_lang_file, 'registernew');
|
||
|
||
$user_name = trim((string)($_POST['user_name'] ?? ''));
|
||
$errors = [];
|
||
|
||
if (empty($user_name))
|
||
{
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_L_EMPTY');
|
||
}
|
||
elseif (self::_nameexists($user_name))
|
||
{
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_L_INUSE');
|
||
}
|
||
|
||
// Если есть ошибки, отдаем их в JSON и прекращаем работу
|
||
if (! empty($errors)) self::_json($errors, true);
|
||
}
|
||
|
||
|
||
/*
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
| checkemail
|
||
|-----------------------------------------------------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
*/
|
||
public static function checkemail ()
|
||
{
|
||
global $AVE_DB, $AVE_Template;
|
||
$AVE_Template->config_load(self::$_lang_file, 'registernew');
|
||
|
||
$email = trim((string)($_POST['email'] ?? ''));
|
||
$errors = [];
|
||
|
||
if (empty($email))
|
||
{
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_EM_EMPTY');
|
||
}
|
||
elseif (self::_emailexist($email))
|
||
{
|
||
$errors[] = $AVE_Template->get_config_vars('LOGIN_WRONG_INUSE');
|
||
}
|
||
|
||
if (! empty($errors)) self::_json($errors, true);
|
||
}
|
||
}
|
||
?>
|