Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / login.php
index f6207762a31f11c3aeec76ca49fef7766ff8777c..c38ca4553232b92fd205ba929d506a6eedd64643 100755 (executable)
--- a/login.php
+++ b/login.php
@@ -25,35 +25,31 @@ $fetchtemplates = array(
        'passwordreset'
 );
 
-define('SVN', '$Id$');
 
 $focus['user'] = 'focus';
 
 require_once('./global.php');
 require_once('./includes/api_user.php');
-require_once('./includes/class_api_error.php');
-
-APIError(array(new API_Error_Handler($message), 'user_cumulative'));
 
 // ###################################################################
 
-if ($bugsys->userinfo['userid'] AND $_REQUEST['do'] != 'logout' AND $_POST['do'] != 'cplogin' AND $_REQUEST['do'] != 'cplogout')
+if (bugdar::$userinfo['userid'] AND $_REQUEST['do'] != 'logout' AND $_POST['do'] != 'cplogin' AND $_REQUEST['do'] != 'cplogout')
 {
-       $message->error(_('You are already logged in.'));
+       $message->error(T('You are already logged in.'));
 }
 
 // ###################################################################
 
 if (empty($_REQUEST['do']))
 {
-       eval('$template->flush("' . $template->fetch('login') . '");');
+       BSTemplate::fetch('login')->evaluate()->flush();
 }
 
 // ###################################################################
 
 if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
 {
-       $keeplogin = $bugsys->input_clean('rememberme', TYPE_BOOL);
+       $keeplogin = $input->inputClean('rememberme', TYPE_BOOL);
        if ($_POST['cplogin'])
        {
                $keeplogin = 0;
@@ -68,20 +64,20 @@ if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
                $url = 'index.php';
        }
        
-       if ($auth->authenticateLogin($bugsys->in['email'], $bugsys->in['password'], $keeplogin))
+       if ($auth->authenticateLogin($input->in['email'], $input->in['password'], $keeplogin))
        {
                if ($_POST['do'] == 'cplogin')
                {
-                       $hash = $funct->rand(90);
+                       $hash = BSFunctions::random(90);
                        $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE dateline < " . (TIMENOW - 3600));
                        $db->query("INSERT INTO " . TABLE_PREFIX . "adminsession (sessionid, userid, dateline) VALUES ('$hash', " . $auth->bugdarUser['userid'] . ", " . TIMENOW . ")");
-                       $funct->cookie(COOKIE_PREFIX . 'adminsession', $hash, false);
+                       BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', $hash, false);
                }
-               $message->redirect(_('Welcome back! You are now logged in.'), $url);
+               $message->redirect(T('Welcome back! You are now logged in.'), $url);
        }
        else
        {
-               $message->error(_('Invalid email or password.'));
+               $message->error(T('Invalid email or password.'));
        }
 }
 
@@ -89,16 +85,16 @@ if ($_POST['do'] == 'login' OR $_POST['do'] == 'cplogin')
 
 if ($_REQUEST['do'] == 'logout')
 {
-       if ($bugsys->userinfo['userid'])
+       if (bugdar::$userinfo['userid'])
        {
-               $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $bugsys->input_escape(COOKIE_PREFIX . 'adminsession') . "'");
+               $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $input->inputEscape(COOKIE_PREFIX . 'adminsession') . "'");
                $auth->clearCookies();
-               $funct->cookie(COOKIE_PREFIX . 'adminsession');
-               $message->redirect(_('You have been logged out.'), ($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php'));
+               BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
+               $message->redirect(T('You have been logged out.'), ($_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php'));
        }
        else
        {
-               $message->error(_('You need to be logged in to access this feature.'));
+               $message->error(T('You need to be logged in to access this feature.'));
        }
 }
 
@@ -106,9 +102,9 @@ if ($_REQUEST['do'] == 'logout')
 
 if ($_POST['do'] == 'sendpw')
 {      
-       $user = new UserAPI($bugsys);
-       $user->set('email', $bugsys->in['email'], true, false); // don't verify so we don't get errors about existing emails
-       $user->set_condition(array('email'));
+       $user = new UserAPI();
+       $user->set('email', $input->in['email'], true, false); // don't verify so we don't get errors about existing emails
+       $user->setCondition(array('email'));
        $user->fetch();
        
        if ($message->hasErrors())
@@ -118,18 +114,18 @@ if ($_POST['do'] == 'sendpw')
        }
        else
        {
-               $activator = $funct->rand(25);
-               $db->query("INSERT INTO " . TABLE_PREFIX . "passwordreset (activatorid, dateline, userid) VALUES ('" . $activator . "', " . TIMENOW . ", " . $user->objdata['userid'] . ")");
-               
-               eval('$email = "' . $template->fetch(FetchEmailPath('passwordreset.xml', $bugsys->datastore['language'][$user->objdata['languageid']]['langcode'])) . '";');
-               $email = $bugsys->xml->parse($email);
+               $activator = BSFunctions::random(25);
+               $db->query("INSERT INTO " . TABLE_PREFIX . "passwordreset (activatorid, dateline, userid) VALUES ('" . $activator . "', " . TIMENOW . ", " . $user->record['userid'] . ")");
                
-               $mail->setSubject($email['email']['subject']['value']);
-               $mail->setBodyText($email['email']['bodyText']['value']);
+               $email = get_email_text('password_reset');
+               $mail = new BSMail();
+               $mail->setSubject($email['subject']);
+               $mail->setBodyText(sprintf($email['bodyText'], $user->record['displayname'], bugdar::$options['trackertitle'], bugdar::$options['trackerurl'], $activator));
+               $mail->setFromAddress(MAIL_FROM_ADDRESS);
+               $mail->setFromName(MAIL_FROM_NAME);
+               $mail->send($user->record['email'], $user->record['displayname']);
                
-               $mail->send($user->objdata['email'], $user->objdata['displayname']);
-               
-               $message->message(sprintf(_('An email has been dispatched to %1$s that contains instructions on how to reset your password.'), $user->objdata['email']));
+               $message->message(sprintf(T('An email has been dispatched to %1$s that contains instructions on how to reset your password.'), $user->record['email']));
        }
 }
 
@@ -137,7 +133,7 @@ if ($_POST['do'] == 'sendpw')
 
 if ($_REQUEST['do'] == 'lostpw')
 {
-       eval('$template->flush("' . $template->fetch('lostpassword') . '");');
+       BSTemplate::fetch('lostpassword')->evaluate()->flush();
 }
 
 // ###################################################################
@@ -148,26 +144,25 @@ if ($_POST['do'] == 'resetpw')
        $db->query("DELETE FROM " . TABLE_PREFIX . "passwordreset WHERE dateline < " . (TIMENOW - 86400));
        
        // now look for ours
-       $activation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "passwordreset WHERE activatorid = '" . $bugsys->input_escape('activator') . "'");
+       $activation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "passwordreset WHERE activatorid = '" . $input->inputEscape('activator') . "'");
        if (!$activation)
        {
                $message->error(L_INVALID_ID);
        }
        
-       $user = new UserAPI($bugsys);
+       $user = new UserAPI();
        $user->set('userid', $activation['userid']);
-       $user->set_condition();
        
-       if ($bugsys->in['fix_password'] != $bugsys->in['confirm_password'])
+       if ($input->in['fix_password'] != $input->in['confirm_password'])
        {
-               $message->addError(_('The passwords you entered do not patch.'));
+               $message->addError(T('The passwords you entered do not patch.'));
        }
-       if (empty($bugsys->in['fix_password']))
+       if (empty($input->in['fix_password']))
        {
-               $message->addError(_('Your new password cannot be empty.'));
+               $message->addError(T('Your new password cannot be empty.'));
        }
        
-       $user->set('password', $bugsys->in['fix_password']);
+       $user->set('password', $input->in['fix_password']);
        
        if (!$message->hasErrors())
        {
@@ -175,7 +170,7 @@ if ($_POST['do'] == 'resetpw')
                $db->query("DELETE FROM " . TABLE_PREFIX . "passwordreset WHERE userid = " . $activation['userid']);
                
                $user->update();
-               $message->redirect(_('Your password has been changed successfully. You will now be redirected to the login page.'), 'login.php');
+               $message->redirect(T('Your password has been changed successfully. You will now be redirected to the login page.'), 'login.php');
        }
        else
        {
@@ -192,13 +187,18 @@ if ($_REQUEST['do'] == 'recoverpw')
        $db->query("DELETE FROM " . TABLE_PREFIX . "passwordreset WHERE dateline < " . (TIMENOW - 86400));
        
        // now look for ours
-       $activation = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "passwordreset WHERE activatorid = '" . $bugsys->input_escape('activator') . "'");
+       $activation = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "passwordreset WHERE activatorid = '" . $input->inputEscape('activator') . "'");
        if (!$activation)
        {
-               $message->error(_('Invalid activation reset key. Please make sure you copied the URL exactly as it appeared in the email.'));
+               $message->error(T('Invalid activation reset key. Please make sure you copied the URL exactly as it appeared in the email.'));
        }
        
-       eval('$template->flush("' . $template->fetch('passwordreset') . '");');
+       $tpl = new BSTemplate('passwordreset');
+       $tpl->vars = array(
+               'activation'    => $activation,
+               'message'               => $message
+       );
+       $tpl->evaluate()->flush();
 }
 
 // ###################################################################
@@ -207,20 +207,14 @@ if ($_REQUEST['do'] == 'cplogout')
 {
        if ($_COOKIE[COOKIE_PREFIX . 'adminsession'])
        {
-               $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $bugsys->input_escape(COOKIE_PREFIX . 'adminsession') . "'");
-               $funct->cookie(COOKIE_PREFIX . 'adminsession');
-               $message->redirect(_('You have been logged out.'), 'admin/');
+               $db->query("DELETE FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $input->inputEscape(COOKIE_PREFIX . 'adminsession') . "'");
+               BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
+               $message->redirect(T('You have been logged out.'), 'admin/');
        }
        else
        {
-               $message->error(_('You are not logged in.'));
+               $message->error(T('You are not logged in.'));
        }
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file