A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.9 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file login.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. define('IN_uF', true);
  11. //include files
  12. include('./config.php');
  13. include('./includes/constants.php');
  14. include('./includes/db.php');
  15. include('./includes/errors.php');
  16. //connect to database
  17. DataBase::db_connect();
  18. include('./includes/sessions.php');
  19. include('./includes/classes/class_user.php');
  20. include('./common.php');
  21. include('./includes/emailer.php');
  22. include('./includes/misc_functions.php');
  23. $default_lang = DefaultLang();
  24. include('./lngs/'.$default_lang.'/main.php');
  25. include('./lngs/'.$default_lang.'/email.php');
  26. include('./includes/classes/secure.php');
  27. $start = TimeGeneration();
  28. SessDelInvalid();
  29. SessRegister();
  30. SessDeleteOld();
  31. foreach ($_POST as $name => $value)
  32. {
  33. if ($forum_config['use_censorlist'])
  34. {
  35. $_POST[$name] = Secure::UseCensorlist($value);
  36. }
  37. }
  38. if (isset($_GET['mode']))
  39. {
  40. switch($_GET['mode'])
  41. {
  42. case 'logout':
  43. {
  44. if ($_SESSION['uid']==0)
  45. {
  46. header('Location: index.php');
  47. }
  48. $uid = $_SESSION['uid'];
  49. $_SESSION['uid']=0;
  50. $_SESSION['sessionid']='0';
  51. SessDelete($uid);
  52. $stop = TimeGeneration();
  53. message_forum($lng['islogout'], 'index.php');
  54. break;
  55. }
  56. case 'login':
  57. {
  58. $default_skin = ViewSkinName();
  59. if ($_SESSION['uid']>0)
  60. {
  61. header('Location: index.php');
  62. }
  63. if (isset($_POST['user']))
  64. {
  65. $user = strip_tags(addslashes($_POST['user']));
  66. $pass = md5(strip_tags($_POST['pass']));
  67. $sql = "SELECT `u_id`, `nick`, `pass` FROM `".USERS_TABLE."` WHERE nick='$user'";
  68. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain user inforamtion');
  69. $result = DataBase::fetch($query);
  70. $nick = $result['nick'];
  71. if ($result['nick']==$user)
  72. {
  73. if ($result['u_id']!='-1')
  74. {
  75. if($pass==$result['pass'])
  76. {
  77. $user_id = $result['u_id'];
  78. $sql = "DELETE FROM `".SESSIONS_TABLE."` WHERE `u_id`='$user_id'";
  79. DataBase::sql_query($sql,GENERAL,'Could not delete session.');
  80. if (User::UserInformation($user_id,'active')==0)
  81. {
  82. SessDelete($_SESSION['uid']);
  83. $_SESSION['uid']='0';
  84. message_forum($lng['account_disabled'],'index.php');
  85. }
  86. $ssid = md5(time().'donothackthiscriptplease!');//session identifier
  87. $_SESSION['uid']=$user_id;
  88. $_SESSION['sessionid']=$ssid;
  89. //session register
  90. $sql = "INSERT INTO `".SESSIONS_TABLE."` VALUES ('', '".$_COOKIE[SESS_NAME]."','$user_id','".time()."')";//query
  91. DataBase::sql_query($sql,GENERAL,'Could not add new session.');//run query
  92. //next...
  93. $sql = "UPDATE `".USERS_TABLE."` SET lastvisit='".time()."' WHERE u_id='$user_id'";//update lastvisit for user
  94. DataBase::sql_query($sql,GENERAL,'Could not update user lastvisit');//run query
  95. $msg = $lng['youareloggedas'].': <b>'.$nick.'</b>';// messaage "login as.."
  96. $skin['pa_link']='';
  97. $stop = TimeGeneration();//generate generation's time
  98. message_forum($msg, 'index.php');//message and require to index.php
  99. }
  100. else
  101. {
  102. $msg = '<br><div align="center" style="width:100%"><span class="fsmall" style="color: red"><b>'.$lng['invalidpass'].'</b></span></div>';
  103. }
  104. }
  105. else
  106. {
  107. message_forum('Access denied.','index.php');
  108. }
  109. }
  110. else
  111. {
  112. $msg = '<br><div align="center" style="width:100%"><span class="fsmall" style="color: red"><b>'.$lng['invalidlogin'].'</b></span></div>';
  113. }
  114. }
  115. else
  116. {
  117. $msg = '';
  118. $_POST['user']='';
  119. }
  120. $skin = array(
  121. 'lforumname' => $lng['forumname'],
  122. 'user' => $lng['user'],
  123. 'lpass' => $lng['lpassw'],
  124. 'lforgotpass' => $lng['lforgot_pass'],
  125. 'llog_in'=> $lng['llog_in'],
  126. 'msg' => $msg
  127. );
  128. $skin = array_push_assoc($skin, GenerateHeader($lng['llogin'],'</a>&gt; <a href="login.php?mode=login" class="navigator">'.$lng['llogin']));
  129. include('./skins/'.$default_skin.'/overall_header.tpl');
  130. include('./skins/'.$default_skin.'/login_body.tpl');
  131. $skin['pa_link']='';
  132. $stop = TimeGeneration();
  133. $skin['queries'] = ShowQueries($start, $stop);
  134. include('./skins/'.$default_skin.'/overall_footer.tpl');
  135. break;
  136. }
  137. case 'forgotpassword':
  138. {
  139. if ($_SESSION['uid']>0)
  140. {
  141. header('Location: index.php');
  142. }
  143. $default_skin = ViewSkinName();
  144. if (!$forum_config['allow_send_email'])
  145. {
  146. message_forum($lng['no_send_newpass'],'index.php');
  147. }
  148. if (isset($_POST['username']))
  149. {
  150. $uid = User::UserIdByNick(htmlspecialchars($_POST['username']));
  151. if (User::UserInformation($uid,'email')!='')
  152. {
  153. $int_rand = rand(1, (strlen(PASSWD_HASH)-$forum_config['newpasswd_len']));
  154. $newpass = substr(PASSWD_HASH, $int_rand, $forum_config['newpasswd_len']);
  155. User::UpdatePassword($uid, md5($newpass));
  156. SendForgotPassEmail($newpass);
  157. message_forum($lng['pass_changed'],'index.php');
  158. }
  159. else
  160. {
  161. message_forum($lng['no_user'],$_SERVER['REQUEST_URI']);
  162. }
  163. }
  164. $skin = array(
  165. 'user' => $lng['user'],
  166. 'lsave' => $lng['save'],
  167. 'pa_link'=>''
  168. );
  169. $skin = array_push_assoc($skin, GenerateHeader($lng['lforgot_pass2'], '</a>&gt; <a href="'.$_SERVER['REQUEST_URI'].'" class="navigator">'.$lng['lforgot_pass2']));
  170. include('./skins/'.$default_skin.'/overall_header.tpl');
  171. include('./skins/'.$default_skin.'/newpass_body.tpl');
  172. $stop = TimeGeneration();
  173. $skin['queries'] = ShowQueries($start, $stop);
  174. include('./skins/'.$default_skin.'/overall_footer.tpl');
  175. break;
  176. }
  177. default:
  178. {
  179. $stop = TimeGeneration();
  180. message_forum($lng['invalidmode'], 'index.php');
  181. }
  182. }
  183. }
  184. else
  185. {
  186. $stop = TimeGeneration();
  187. message_forum($lng['invalidmode'], 'index.php');
  188. }
  189. ?>