r303: Added SVN constant to user files; now ISSO debug information shows SVN details.
[bugdar.git] / login.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 $fetchtemplates = array(
14 'login'
15 );
16
17 define('SVN', '$Id$');
18
19 require_once('./global.php');
20
21 // ###################################################################
22
23 if ($bugsys->userinfo['userid'] AND $_REQUEST['do'] != 'logout' AND $_POST['do'] != 'cplogin' AND $_REQUEST['do'] != 'cplogout')
24 {
25 $message->error('You are already logged in.');
26 }
27
28 // ###################################################################
29
30 if (empty($_REQUEST['do']))
31 {
32 eval('$template->flush("' . $template->fetch('login') . '");');
33 }
34
35 // ###################################################################
36
37 if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
38 {
39 $keeplogin = intval($bugsys->in['rememberme']);
40 if ($_POST['cplogin'])
41 {
42 $keeplogin = 0;
43 }
44
45 if ($_SERVER['HTTP_REFERER'] AND !$_POST['goindex'])
46 {
47 $url = $_SERVER['HTTP_REFERER'];
48 }
49 else
50 {
51 $url = 'index.php';
52 }
53
54 $userinfo = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in['email'] . "'");
55 if (md5(md5($bugsys->in['password']) . md5($userinfo['salt'])) == $userinfo['password'])
56 {
57 if (!$bugsys->userinfo['userid'])
58 {
59 $funct->cookie(COOKIE_PREFIX . 'userid', $userinfo['userid'], $keeplogin);
60 $funct->cookie(COOKIE_PREFIX . 'authkey', $userinfo['authkey'], $keeplogin);
61 }
62
63 if ($_POST['do'] == 'cplogin')
64 {
65 $funct->cookie(COOKIE_PREFIX . 'adminsession', md5(md5($userinfo['authkey']) . md5($userinfo['email']) . md5($userinfo['userid'])), false);
66 }
67 }
68 else
69 {
70 if (!$bugsys->userinfo['userid'])
71 {
72 $funct->cookie(COOKIE_PREFIX . 'userid');
73 $funct->cookie(COOKIE_PREFIX . 'authkey');
74 }
75
76 $message->error('Invalid email or password.');
77 }
78
79 $message->redirect('You are now logged in :-)', $url);
80 }
81
82 // ###################################################################
83
84 if ($_REQUEST['do'] == 'logout')
85 {
86 if ($bugsys->userinfo['userid'])
87 {
88 $funct->cookie(COOKIE_PREFIX . 'userid');
89 $funct->cookie(COOKIE_PREFIX . 'authkey');
90 $funct->cookie(COOKIE_PREFIX . 'adminsession');
91 }
92 else
93 {
94 $message->error('You need to be logged in!');
95 }
96 }
97
98 // ###################################################################
99
100 if ($_REQUEST['do'] == 'cplogout')
101 {
102 if ($_COOKIE[COOKIE_PREFIX . 'adminsession'])
103 {
104 $funct->cookie(COOKIE_PREFIX . 'adminsession');
105 $message->redirect('logged out', 'admin/');
106 }
107 else
108 {
109 $message->error('you are not logged in');
110 }
111 }
112
113 /*=====================================================================*\
114 || ###################################################################
115 || # $HeadURL$
116 || # $Id$
117 || ###################################################################
118 \*=====================================================================*/
119 ?>