Просмотр файла shcms/authorization.php

Размер файла: 8.11Kb
  1. <?
  2. /*
  3. =============================================
  4. Движок: SHCMS Engine
  5. =============================================
  6. Название файла: Авторизация
  7. =============================================
  8. Official website: http://shcms.ru
  9. =============================================
  10. */
  11.  
  12. define('SHCMS', true);
  13. include_once'../system/inc/basic_settings.php';
  14. $shcmsengine['title'] = 'Авторизация на сайте';
  15. include_once'../template/head.php';
  16.  
  17. if(!$settings_shcms['act_aut']) {
  18.  
  19. errors("Авторизация временно отключено");
  20. include_once'../template/foot.php';
  21. exit;
  22. }
  23.  
  24.  
  25. if(isset($user_id)){
  26. header("Refresh:1; url=/index.php");
  27. exit();
  28. }
  29.  
  30. if(isset($_POST['submit'])) {
  31. $submit = $_POST['submit'];
  32. }
  33.  
  34. if(isset($submit)) {
  35. if($_POST['login'])
  36. {
  37. $login_aut = $_POST['login'];
  38. }
  39. if($_POST['email'])
  40. {
  41. $email_aut = $_POST['email'] ;
  42. }
  43.  
  44. if($_POST['id'])
  45. {
  46. $id_aut = $_POST['id'];
  47. }
  48.  
  49. if($_REQUEST['password'])
  50. {
  51. $password_aut = $_REQUEST['password'];
  52. }
  53.  
  54. $user_mem = isset($_POST['save_co']) ? 1 : 0;
  55. $user_code = isset($_POST['code']) ? trim($_POST['code']) : NULL;
  56.  
  57. if($settings_shcms['id_aut'] == 1)
  58. {
  59. if (!$id_aut)
  60. {
  61. echo'<div class="errors">Введите ID</div>';
  62. header("Refresh: 1; url=?");
  63. include_once'../template/foot.php';
  64. exit();
  65. }
  66. }
  67. elseif($settings_shcms['id_aut'] == 2)
  68. {
  69. if (!$email_aut)
  70. {
  71. echo'<div class="errors">Введите Email</div>';
  72. header("Refresh: 1; url=?");
  73. include_once'../template/foot.php';
  74. exit();
  75. }
  76. }
  77. elseif($settings_shcms['id_aut'] == 0)
  78. {
  79. if (!$login_aut)
  80. {
  81. echo'<div class="errors">Введите логин</div>';
  82. header("Refresh: 1; url=?");
  83. include_once'../template/foot.php';
  84. exit();
  85. }
  86. }
  87. if (($login_aut || $id) && !$password_aut)
  88. {
  89. echo '<div class="errors">Введите пороль</div>';
  90. header("Refresh: 1; url=?");
  91. include_once'../template/foot.php';
  92. exit();
  93. }
  94. if ($login_aut && (strlen($login_aut) < 2 || strlen($login_aut) > 20))
  95. {
  96. echo '<div class="errors">Длина логина не должно превышать больше 20 символов</div>';
  97. header("Refresh: 1; url=?");
  98. include_once'../template/foot.php';
  99. exit();
  100. }
  101. if ($password_aut && (strlen($password_aut) < 3 || strlen($password_aut) > 15))
  102. {
  103. echo '<div class="errors">Длина пороля не должно превышать больше 15 символов</div>';
  104. header("Refresh: 1; url=?");
  105. include_once'../template/foot.php';
  106. exit();
  107. }
  108. /*
  109. --------------------------------------
  110. Капча. Разрещено отображать и скрывать
  111. --------------------------------------
  112. */
  113. if($settings_shcms['captcha_aut'] == 1)
  114. {
  115. if(isset($_POST['kod']))
  116. {
  117. $antibot = isset($_POST['kod']) ? trim($_POST['kod']) : '';
  118. if (empty($antibot) || strlen($antibot) < 3)
  119. {
  120. echo '<div class="errors">Код безопастности не введен!</div>';
  121. header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
  122. include_once'../template/foot.php';
  123. exit();
  124. }
  125. elseif ($antibot != $_SESSION['code'])
  126. {
  127. errors('Код безопасности не соответствует отображённому');
  128. header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
  129. include_once'../template/foot.php';
  130. exit();
  131. }
  132. unset($_SESSION['code']);
  133. }
  134. }
  135.  
  136. /*
  137. ---------------------
  138. Авторизация по ID
  139. ---------------------
  140. */
  141. if($settings_shcms['id_aut'] == 1)
  142. {
  143. $sql = $id ? "`id` = '$id'" : "`id`='" . rus_lat(strtolower($id_aut)) ."'";
  144. }
  145. /*
  146. ---------------------
  147. Авторизация по Email
  148. ---------------------
  149. */
  150. elseif($settings_shcms['id_aut'] == 2)
  151. {
  152. $sql = $id ? "`id` = '$id'" : "`email`='" . rus_lat(strtolower($email_aut)) ."'";
  153. }
  154. /*
  155. ---------------------
  156. Авторизация по Login
  157. ---------------------
  158. */
  159. elseif($settings_shcms['id_aut'] == 0)
  160. {
  161. $sql = $id ? "`id` = '$id'" : "`login`='" . rus_lat(strtolower($login_aut)) ."'";
  162. }
  163.  
  164. $shcms_aut = mysql_query("SELECT * FROM `users` WHERE $sql LIMIT 1");
  165. if (mysql_num_rows($shcms_aut))
  166. {
  167. $user = mysql_fetch_array($shcms_aut);
  168. if (md5(md5($password_aut)) == $user['password'])
  169. {
  170. if ($_POST['save_co'] == 1) {
  171. $COOKIE_ID = base64_encode($user['id']);
  172. $COOKIE_PASS = md5($password_aut);
  173. setcookie("COOKIE_ID", $COOKIE_ID, time() + 3600 * 24 * 365);
  174. setcookie("COOKIE_PASS", $COOKIE_PASS, time() + 3600 * 24 * 365);
  175. }
  176. $_SESSION['SESSION_ID'] = $user['id'];
  177. $_SESSION['SESSION_PASS'] = md5(md5($password_aut));
  178. mysql_query("UPDATE `users` SET `sestime` = '".time()."' WHERE `id` = '" . $user['id'] . "'");
  179. mysql_query("UPDATE `users` SET `datelast` = ".time()." WHERE `id` = '".$user['id']."' LIMIT 1");
  180. mysql_query("INSERT INTO `logs_aut` (`user_id`,`port`,`ip`,`method`,`time`) VALUES ('$user[id]','$server_port','$vi_shcms','$method_logs','".time()."')");
  181. if ($user['lastdate'] < (time() - 3600))
  182. {
  183. echo '<div class="actshcms">Вы успешно авторизованы</div>';
  184. header("Refresh: 1; url=/index.php");
  185. include_once'../template/foot.php';
  186. exit();
  187. }
  188. }
  189. else
  190. {
  191. echo '<div class="errors">Ошибка авторизации</div>';
  192. header("Refresh: 1; url=?");
  193. include_once'../template/foot.php';
  194. exit();
  195. }
  196. }
  197. else
  198. {
  199. echo '<div class="errors">Вы ввели неправильный логин и пороль</div>';
  200. header('Refresh: 1; url=authorization.php?' . $conservation . '&' );
  201. include_once'../template/foot.php';
  202. exit();
  203. }
  204.  
  205. }
  206. else
  207. {
  208.  
  209. echo '<form action="?'.$conservation.'" method="post">';
  210. if($settings_shcms['id_aut'] == 1)
  211. {
  212. echo 'ID:<br/><input type="text" name="id" value="'.$id_aut.'" maxlength="20"/><br/>';
  213. }
  214. elseif($settings_shcms['id_aut'] == 2)
  215. {
  216. echo 'Email:<br/><input type="text" name="email" value="'.$email_aut.'" maxlength="20"/><br/>';
  217. }
  218. elseif($settings_shcms['id_aut'] == 0)
  219. {
  220. echo 'Логин:<br/><input type="text" name="login" value="'.$login_aut.'" maxlength="20"/><br/>';
  221. }
  222. echo 'Пароль:<br/><input type="password" name="password" maxlength="20"/><br/>';
  223. echo '<input type="checkbox" name="save_co" value="1" checked="checked"/>Запомнить<br/>';
  224. if($settings_shcms['captcha_aut'] == 1)
  225. {
  226. echo '<script type="text/javascript">
  227. src="/shcms/antibot.php?r=rand(1000,9999)";
  228. function reload(){
  229. document.captcha.src="/shcms/antibot.php?r=rand(1000,9999)";
  230. document.captcha.src=src+"?rand="+Math.random(); } </script>';
  231. echo '<img name="captcha" class="midside" alt="Код безопастности" src="'.DIR_SHCMS.'antibot.php?r='.rand(1000, 9999) .'"/><br />';
  232. echo '<a href="javascript:void(0)" onclick="reload()">обновить, если не виден код</a><br/>';
  233. echo '<input type="text" style="width:115px" size="5" maxlength="5" name="kod"/><br/>';
  234. }
  235. echo '<input type="submit" name="submit" value="Войти"/></form>' ;
  236. echo '<div class="posts">Если вы забыли пороль: <a href="flogged.php">Восстановить пороль</a></div>';
  237. echo '<div class="posts">Если у вас нет аккаунта: <a href="registration.php">Создать аккаунт</a></div>';
  238.  
  239. }
  240.  
  241. include_once'../template/foot.php';
  242. ?>