2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright 2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 $fetchtemplates = array(
26 define('SVN', '$Id$');
28 $focus['user
'] = 'focus
';
30 require_once('./global.php
');
32 // ###################################################################
34 if ($bugsys->userinfo['userid
'] AND $_REQUEST['do'] != 'logout
' AND $_POST['do'] != 'cplogin
' AND $_REQUEST['do'] != 'cplogout
')
36 $message->error(_('You are already logged in
.'));
39 // ###################################################################
41 if (empty($_REQUEST['do']))
43 eval('$template->flush("' . $template->fetch('login') . '");');
46 // ###################################################################
48 if ($_POST['do'] == 'login
' OR $_POST['do'] == 'cplogin
')
50 $keeplogin = $bugsys->input_clean('rememberme
', TYPE_BOOL);
51 if ($_POST['cplogin
'])
56 if ($_SERVER['HTTP_REFERER
'] AND !$_POST['goindex
'])
58 $url = $_SERVER['HTTP_REFERER
'];
65 $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $bugsys->input_escape('email') . "'");
66 if (md5(md5($bugsys->in['password
']) . md5($userinfo['salt
'])) == $userinfo['password
'])
68 if (!$bugsys->userinfo['userid
'])
70 $funct->cookie(COOKIE_PREFIX . 'userid
', $userinfo['userid
'], $keeplogin);
71 $funct->cookie(COOKIE_PREFIX . 'authkey
', $userinfo['authkey
'], $keeplogin);
74 if ($_POST['do'] == 'cplogin
')
76 $funct->cookie(COOKIE_PREFIX . 'adminsession
', md5(md5($userinfo['authkey
']) . md5(gmdate('F j
, Y
@ H
'))), false);
81 if (!$bugsys->userinfo['userid
'])
83 $funct->cookie(COOKIE_PREFIX . 'userid
');
84 $funct->cookie(COOKIE_PREFIX . 'authkey
');
87 $message->error(_('Invalid email
or password
.'));
90 $message->redirect(_('Welcome back
! You are now logged in
.'), $url);
93 // ###################################################################
95 if ($_REQUEST['do'] == 'logout
')
97 if ($bugsys->userinfo['userid
'])
99 $funct->cookie(COOKIE_PREFIX . 'userid
');
100 $funct->cookie(COOKIE_PREFIX . 'authkey
');
101 $funct->cookie(COOKIE_PREFIX . 'adminsession
');
102 $message->redirect(_('You have been logged out
.'), ($_SERVER['HTTP_REFERER
'] ? $_SERVER['HTTP_REFERER
'] : 'index
.php
'));
106 $message->error(_('You need to be logged in to access this feature
.'));
110 // ###################################################################
112 if ($_REQUEST['do'] == 'cplogout
')
114 if ($_COOKIE[COOKIE_PREFIX . 'adminsession
'])
116 $funct->cookie(COOKIE_PREFIX . 'adminsession
');
117 $message->redirect(_('You have been logged out
.'), 'admin
/');
121 $message->error(_('You are not logged in
.'));
125 /*=====================================================================*\
126 || ###################################################################
129 || ###################################################################
130 \*=====================================================================*/