2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright 2002-2007 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 2 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(
28 define('SVN', '$Id$');
30 $focus['user'] = 'focus';
32 require_once('./global.php');
33 require_once('./includes/api_user.php');
34 require_once('./includes/class_api_error.php');
36 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
38 // ###################################################################
40 if ($bugsys->userinfo
['userid'] AND $_REQUEST['do'] != 'logout' AND $_POST['do'] != 'cplogin' AND $_REQUEST['do'] != 'cplogout')
42 $message->error(T('You are already logged in.'));
45 // ###################################################################
47 if (empty($_REQUEST['do']))
49 eval('$template->flush("' . $template->fetch('login') . '");');
52 // ###################################################################
54 if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
56 $keeplogin = $bugsys->input_clean('rememberme', TYPE_BOOL
);
57 if ($_POST['cplogin'])
62 if ($_SERVER['HTTP_REFERER'] AND !$_POST['goindex'])
64 $url = $_SERVER['HTTP_REFERER'];
71 if ($auth->authenticateLogin($bugsys->in
['email'], $bugsys->in
['password'], $keeplogin))
73 if ($_POST['do'] == 'cplogin')
75 $hash = $funct->rand(90);
76 $db->query("DELETE FROM " . TABLE_PREFIX
. "adminsession WHERE dateline < " . (TIMENOW
- 3600));
77 $db->query("INSERT INTO " . TABLE_PREFIX
. "adminsession (sessionid, userid, dateline) VALUES ('$hash', " . $auth->bugdarUser
['userid'] . ", " . TIMENOW
. ")");
78 $funct->cookie(COOKIE_PREFIX
. 'adminsession', $hash, false
);
80 $message->redirect(T('Welcome back! You are now logged in.'), $url);
84 $message->error(T('Invalid email or password.'));
88 // ###################################################################
90 if ($_REQUEST['do'] == 'logout')
92 if ($bugsys->userinfo
['userid'])
94 $db->query("DELETE FROM " . TABLE_PREFIX
. "adminsession WHERE sessionid = '" . $bugsys->input_escape(COOKIE_PREFIX
. 'adminsession') . "'");
95 $auth->clearCookies();
96 $funct->cookie(COOKIE_PREFIX
. 'adminsession');
97 $message->redirect(T('You have been logged out.'), ($_SERVER['HTTP_REFERER'] ?
$_SERVER['HTTP_REFERER'] : 'index.php'));
101 $message->error(T('You need to be logged in to access this feature.'));
105 // ###################################################################
107 if ($_POST['do'] == 'sendpw')
109 $user = new UserAPI($bugsys);
110 $user->set('email', $bugsys->in
['email'], true
, false
); // don't verify so we don't get errors about existing emails
111 $user->set_condition(array('email'));
114 if ($message->hasErrors())
116 $show['lostpwerror'] = true
;
117 $_REQUEST['do'] = 'lostpw';
121 $activator = $funct->rand(25);
122 $db->query("INSERT INTO " . TABLE_PREFIX
. "passwordreset (activatorid, dateline, userid) VALUES ('" . $activator . "', " . TIMENOW
. ", " . $user->objdata
['userid'] . ")");
124 eval('$email = "' . $template->fetch(FetchEmailPath('passwordreset.xml', $bugsys->datastore
['language'][$user->objdata
['languageid']]['langcode'])) . '";');
125 $email = $bugsys->xml
->parse($email);
127 $mail->setSubject($email['email']['subject']['value']);
128 $mail->setBodyText($email['email']['bodyText']['value']);
130 $mail->send($user->objdata
['email'], $user->objdata
['displayname']);
132 $message->message(sprintf(T('An email has been dispatched to %1$s that contains instructions on how to reset your password.'), $user->objdata
['email']));
136 // ###################################################################
138 if ($_REQUEST['do'] == 'lostpw')
140 eval('$template->flush("' . $template->fetch('lostpassword') . '");');
143 // ###################################################################
145 if ($_POST['do'] == 'resetpw')
147 // remove old activators
148 $db->query("DELETE FROM " . TABLE_PREFIX
. "passwordreset WHERE dateline < " . (TIMENOW
- 86400));
151 $activation = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "passwordreset WHERE activatorid = '" . $bugsys->input_escape('activator') . "'");
154 $message->error(L_INVALID_ID
);
157 $user = new UserAPI($bugsys);
158 $user->set('userid', $activation['userid']);
159 $user->set_condition();
161 if ($bugsys->in
['fix_password'] != $bugsys->in
['confirm_password'])
163 $message->addError(T('The passwords you entered do not patch.'));
165 if (empty($bugsys->in
['fix_password']))
167 $message->addError(T('Your new password cannot be empty.'));
170 $user->set('password', $bugsys->in
['fix_password']);
172 if (!$message->hasErrors())
174 // remove old other activators for this user
175 $db->query("DELETE FROM " . TABLE_PREFIX
. "passwordreset WHERE userid = " . $activation['userid']);
178 $message->redirect(T('Your password has been changed successfully. You will now be redirected to the login page.'), 'login.php');
182 $show['errors'] = true
;
183 $_REQUEST['do'] = 'recoverpw';
187 // ###################################################################
189 if ($_REQUEST['do'] == 'recoverpw')
191 // remove old activators
192 $db->query("DELETE FROM " . TABLE_PREFIX
. "passwordreset WHERE dateline < " . (TIMENOW
- 86400));
195 $activation = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "passwordreset WHERE activatorid = '" . $bugsys->input_escape('activator') . "'");
198 $message->error(T('Invalid activation reset key. Please make sure you copied the URL exactly as it appeared in the email.'));
201 eval('$template->flush("' . $template->fetch('passwordreset') . '");');
204 // ###################################################################
206 if ($_REQUEST['do'] == 'cplogout')
208 if ($_COOKIE[COOKIE_PREFIX
. 'adminsession'])
210 $db->query("DELETE FROM " . TABLE_PREFIX
. "adminsession WHERE sessionid = '" . $bugsys->input_escape(COOKIE_PREFIX
. 'adminsession') . "'");
211 $funct->cookie(COOKIE_PREFIX
. 'adminsession');
212 $message->redirect(T('You have been logged out.'), 'admin/');
216 $message->error(T('You are not logged in.'));
220 /*=====================================================================*\
221 || ###################################################################
224 || ###################################################################
225 \*=====================================================================*/