Размер файла: 8.11Kb
- <?
- /*
- =============================================
- Движок: SHCMS Engine
- =============================================
- Название файла: Авторизация
- =============================================
- Official website: http://shcms.ru
- =============================================
- */
-
- define('SHCMS', true);
- include_once'../system/inc/basic_settings.php';
- $shcmsengine['title'] = 'Авторизация на сайте';
- include_once'../template/head.php';
-
- if(!$settings_shcms['act_aut']) {
-
- errors("Авторизация временно отключено");
- include_once'../template/foot.php';
- exit;
- }
-
-
- if(isset($user_id)){
- header("Refresh:1; url=/index.php");
- exit();
- }
-
- if(isset($_POST['submit'])) {
- $submit = $_POST['submit'];
- }
-
- if(isset($submit)) {
-
- if($_POST['login'])
- {
- $login_aut = $_POST['login'];
- }
- if($_POST['email'])
- {
- $email_aut = $_POST['email'] ;
- }
-
- if($_POST['id'])
- {
- $id_aut = $_POST['id'];
- }
-
- if($_REQUEST['password'])
- {
- $password_aut = $_REQUEST['password'];
- }
-
- $user_mem = isset($_POST['save_co']) ? 1 : 0;
- $user_code = isset($_POST['code']) ? trim($_POST['code']) : NULL;
-
- if($settings_shcms['id_aut'] == 1)
- {
- if (!$id_aut)
- {
- echo'<div class="errors">Введите ID</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- }
- elseif($settings_shcms['id_aut'] == 2)
- {
- if (!$email_aut)
- {
- echo'<div class="errors">Введите Email</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- }
- elseif($settings_shcms['id_aut'] == 0)
- {
- if (!$login_aut)
- {
- echo'<div class="errors">Введите логин</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- }
- if (($login_aut || $id) && !$password_aut)
- {
- echo '<div class="errors">Введите пороль</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- if ($login_aut && (strlen($login_aut) < 2 || strlen($login_aut) > 20))
- {
- echo '<div class="errors">Длина логина не должно превышать больше 20 символов</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- if ($password_aut && (strlen($password_aut) < 3 || strlen($password_aut) > 15))
- {
- echo '<div class="errors">Длина пороля не должно превышать больше 15 символов</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- /*
- --------------------------------------
- Капча. Разрещено отображать и скрывать
- --------------------------------------
- */
- if($settings_shcms['captcha_aut'] == 1)
- {
- if(isset($_POST['kod']))
- {
- $antibot = isset($_POST['kod']) ? trim($_POST['kod']) : '';
-
- if (empty($antibot) || strlen($antibot) < 3)
- {
- echo '<div class="errors">Код безопастности не введен!</div>';
- header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
- include_once'../template/foot.php';
- exit();
- }
- elseif ($antibot != $_SESSION['code'])
- {
- errors('Код безопасности не соответствует отображённому');
- header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
- include_once'../template/foot.php';
- exit();
- }
- unset($_SESSION['code']);
- }
- }
-
- /*
- ---------------------
- Авторизация по ID
- ---------------------
- */
- if($settings_shcms['id_aut'] == 1)
- {
- $sql = $id ? "`id` = '$id'" : "`id`='" . rus_lat(strtolower($id_aut)) ."'";
- }
- /*
- ---------------------
- Авторизация по Email
- ---------------------
- */
- elseif($settings_shcms['id_aut'] == 2)
- {
- $sql = $id ? "`id` = '$id'" : "`email`='" . rus_lat(strtolower($email_aut)) ."'";
- }
- /*
- ---------------------
- Авторизация по Login
- ---------------------
- */
- elseif($settings_shcms['id_aut'] == 0)
- {
- $sql = $id ? "`id` = '$id'" : "`login`='" . rus_lat(strtolower($login_aut)) ."'";
- }
-
- $shcms_aut = mysql_query("SELECT * FROM `users` WHERE $sql LIMIT 1");
-
- if (mysql_num_rows($shcms_aut))
- {
- $user = mysql_fetch_array($shcms_aut);
-
- if (md5(md5($password_aut)) == $user['password'])
- {
- if ($_POST['save_co'] == 1) {
- $COOKIE_ID = base64_encode($user['id']);
- $COOKIE_PASS = md5($password_aut);
- setcookie("COOKIE_ID", $COOKIE_ID, time() + 3600 * 24 * 365);
- setcookie("COOKIE_PASS", $COOKIE_PASS, time() + 3600 * 24 * 365);
- }
- $_SESSION['SESSION_ID'] = $user['id'];
- $_SESSION['SESSION_PASS'] = md5(md5($password_aut));
-
- mysql_query("UPDATE `users` SET `sestime` = '".time()."' WHERE `id` = '" . $user['id'] . "'");
- mysql_query("UPDATE `users` SET `datelast` = ".time()." WHERE `id` = '".$user['id']."' LIMIT 1");
- mysql_query("INSERT INTO `logs_aut` (`user_id`,`port`,`ip`,`method`,`time`) VALUES ('$user[id]','$server_port','$vi_shcms','$method_logs','".time()."')");
-
- if ($user['lastdate'] < (time() - 3600))
- {
- echo '<div class="actshcms">Вы успешно авторизованы</div>';
- header("Refresh: 1; url=/index.php");
- include_once'../template/foot.php';
- exit();
- }
- }
- else
- {
- echo '<div class="errors">Ошибка авторизации</div>';
- header("Refresh: 1; url=?");
- include_once'../template/foot.php';
- exit();
- }
- }
- else
- {
- echo '<div class="errors">Вы ввели неправильный логин и пороль</div>';
- header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
- include_once'../template/foot.php';
- exit();
- }
-
- }
- else
- {
-
-
- echo '<form action="?'.$conservation.'" method="post">';
- if($settings_shcms['id_aut'] == 1)
- {
- echo 'ID:<br/><input type="text" name="id" value="'.$id_aut.'" maxlength="20"/><br/>';
- }
- elseif($settings_shcms['id_aut'] == 2)
- {
- echo 'Email:<br/><input type="text" name="email" value="'.$email_aut.'" maxlength="20"/><br/>';
- }
- elseif($settings_shcms['id_aut'] == 0)
- {
- echo 'Логин:<br/><input type="text" name="login" value="'.$login_aut.'" maxlength="20"/><br/>';
- }
- echo 'Пароль:<br/><input type="password" name="password" maxlength="20"/><br/>';
- echo '<input type="checkbox" name="save_co" value="1" checked="checked"/>Запомнить<br/>';
-
- if($settings_shcms['captcha_aut'] == 1)
- {
- echo '<script type="text/javascript">
- src="/shcms/antibot.php?r=rand(1000,9999)";
- function reload(){
- document.captcha.src="/shcms/antibot.php?r=rand(1000,9999)";
- document.captcha.src=src+"?rand="+Math.random(); } </script>';
- echo '<img name="captcha" class="midside" alt="Код безопастности" src="'.DIR_SHCMS.'antibot.php?r='.rand(1000, 9999) .'"/><br />';
- echo '<a href="javascript:void(0)" onclick="reload()">обновить, если не виден код</a><br/>';
- echo '<input type="text" style="width:115px" size="5" maxlength="5" name="kod"/><br/>';
- }
- echo '<input type="submit" name="submit" value="Войти"/></form>' ;
- echo '<div class="posts">Если вы забыли пороль: <a href="flogged.php">Восстановить пороль</a></div>';
- echo '<div class="posts">Если у вас нет аккаунта: <a href="registration.php">Создать аккаунт</a></div>';
-
- }
-
- include_once'../template/foot.php';
- ?>