r176: Switching to the Message_Reporter::redirect() method of redirection
[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 require_once('./global.php');
18
19 // ###################################################################
20
21 if ($bugsys->userinfo['userid'] AND $_REQUEST['do'] != 'logout' AND $_POST['do'] != 'cplogin' AND $_REQUEST['do'] != 'cplogout')
22 {
23 $message->error('You are already logged in.');
24 }
25
26 // ###################################################################
27
28 if (empty($_REQUEST['do']))
29 {
30 eval('$template->flush("' . $template->fetch('login') . '");');
31 }
32
33 // ###################################################################
34
35 if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
36 {
37 $keeplogin = intval($bugsys->in['rememberme']);
38 if ($_POST['cplogin'])
39 {
40 $keeplogin = 0;
41 }
42
43 if ($_SERVER['HTTP_REFERER'] AND !$_POST['goindex'])
44 {
45 $url = $_SERVER['HTTP_REFERER'];
46 }
47 else
48 {
49 $url = 'index.php';
50 }
51
52 $userinfo = $db->query_first("SELECT * FROM user WHERE email = '" . $bugsys->in['email'] . "'");
53 if (md5(md5($bugsys->in['password']) . md5($userinfo['salt'])) == $userinfo['password'])
54 {
55 if (!$bugsys->userinfo['userid'])
56 {
57 $funct->cookie(COOKIE_PREFIX . 'userid', $userinfo['userid'], $keeplogin);
58 $funct->cookie(COOKIE_PREFIX . 'authkey', $userinfo['authkey'], $keeplogin);
59 }
60
61 if ($_POST['do'] == 'cplogin')
62 {
63 $funct->cookie(COOKIE_PREFIX . 'adminsession', md5(md5($userinfo['authkey']) . md5($userinfo['email']) . md5($userinfo['userid'])), false);
64 }
65 }
66 else
67 {
68 if (!$bugsys->userinfo['userid'])
69 {
70 $funct->cookie(COOKIE_PREFIX . 'userid');
71 $funct->cookie(COOKIE_PREFIX . 'authkey');
72 }
73
74 $message->error('Invalid email or password.');
75 }
76
77 $message->redirect('You are now logged in :-)', $url);
78 }
79
80 // ###################################################################
81
82 if ($_REQUEST['do'] == 'logout')
83 {
84 if ($bugsys->userinfo['userid'])
85 {
86 $funct->cookie(COOKIE_PREFIX . 'userid');
87 $funct->cookie(COOKIE_PREFIX . 'authkey');
88 $funct->cookie(COOKIE_PREFIX . 'adminsession');
89 }
90 else
91 {
92 $message->error('You need to be logged in!');
93 }
94 }
95
96 // ###################################################################
97
98 if ($_REQUEST['do'] == 'cplogout')
99 {
100 if ($_COOKIE[COOKIE_PREFIX . 'adminsession'])
101 {
102 $funct->cookie(COOKIE_PREFIX . 'adminsession');
103 $message->redirect('logged out', 'admin/');
104 }
105 else
106 {
107 $message->error('you are not logged in');
108 }
109 }
110
111 /*=====================================================================*\
112 || ###################################################################
113 || # $HeadURL$
114 || # $Id$
115 || ###################################################################
116 \*=====================================================================*/
117 ?>