function &singleton() { static $baskets; if (isset($_COOKIE['basketID']) && is_numeric($_COOKIE['basketID'])) { $sql = "SELECT COUNT(*) AS total\n FROM basket\n WHERE basketID=" . $_COOKIE['basketID']; $result = $this->db->getOne($sql); if (!PEAR::isError($result) && is_numeric($result) && $result > 0) { $basketID = $_COOKIE['basketID']; if (isset($baskets[$basketID]) && is_object($baskets[$basketID])) { // Do nothing - the basket already exists } else { $baskets[$basketID] =& new JxBasket($basketID); } } else { $basketID = 0; } } if ($basketID == 0) { $basketID = JxCreateId('basket', 'basketID'); $userID = $user->userID; $posted = time(); $type = 0; if ((int) $basketID > 0) { $sql = "INSERT INTO basket\n SET basketID='" . (int) $basketID . "',\n userID='" . $userID . "',\n posted='" . $posted . "',\n type='" . $type . "'"; $result = $this->db->query($sql); if (PEAR::isError($result)) { return PEAR::raiseError('Unable to create basket'); } else { JxHttp::setCookie('basketID', $basketID); } } $baskets[$basketID] =& new JxBasket($basketID); } return $baskets[$basketID]; }
function __default() { $session = new JxSession(); if (!JxSession::isError($session)) { $session->destroy(); JxHttp::redirect(); } }
function __default() { $this->form =& new JxHtmlForm(); $this->page->title = 'Login'; $container =& new JxHtmlFormContainer('Login'); $container->label = 'Login'; if (isset($_GET['email']) && !isset($_POST['login'])) { $_POST['login'] = $_GET['email']; } if (isset($_GET['password']) && !isset($_POST['password'])) { $_POST['password'] = $_GET['password']; } if (JX_LOGIN_TYPE == 'email') { $field =& new JxFieldEmail('login', $_POST['login']); $field->label = 'Email'; $field->required = true; $container->addComponent($field); } elseif (JX_LOGIN_TYPE == 'username') { $field =& new JxFieldString('login', $_POST['login']); $field->label = 'Username'; $field->required = true; $container->addComponent($field); } else { return new PEAR_Error('Invalid JX_LOGIN_TYPE: ' . JX_LOGIN_TYPE); } $field =& new JxFieldPassword('password', $_POST['password'], 15, 15); $field->label = '&Password'; $field->required = true; $container->addComponent($field); $field =& new JxFieldSubmit('button', 'Login!'); $container->addComponent($field); $this->form->addComponent($container); if (is_array($_POST) && count($_POST)) { $sql = "SELECT *\n FROM users\n WHERE " . JX_LOGIN_TYPE . "='" . $_POST['login'] . "'"; $result = $this->db->getRow($sql); if (!JxUser::isError($result)) { if ($result['password'] != $_POST['password']) { $this->form->throwError('password', 'Invalid password'); } } else { $this->form->throwError('login', 'Invalid login'); } } if (!$this->form->isValid()) { $this->setData('loginForm', $this->form->getForm()); } else { $data = $this->form->getData(); $session =& new JxSession(); if (!JxSession::isError($session)) { $session->create($data['login']); JxHttp::redirect(); } } }
/** * create * * Create a session for the given $userID. This function sets the two * needed cookies for sessions as well as updating the database. * * @author Joe Stump <*****@*****.**> * @access public * @param int $userID See users table.userID * @return void */ function create($userID) { $user =& new JxUser($userID); if ($user->userID > 0) { $sessionID = md5(uniqid(JX_SESS_KEY . $user->password)); $sql = "INSERT \n INTO users_sessions\n SET userID='" . $user->userID . "',\n sessionID='{$sessionID}',\n posted='" . time() . "'"; $result = $this->db->query($sql); if (!DB::isError($result)) { JxHttp::setCookie('jax_sessionID', $sessionID); JxHttp::setCookie('jax_userID', $user->userID); } } }
function __default() { $this->form =& new JxHtmlForm(); $container =& new JxHtmlFormContainer('AccInfo'); $container->label = 'Account Information'; $field =& new JxFieldString('username', $_POST['username']); $field->mustNotMatch = '[^a-z0-9]'; $field->label = 'Username'; $field->required = true; $container->addComponent($field); $field =& new JxFieldEmail('email', $_POST['email']); $field->required = true; $container->addComponent($field); $field =& new JxFieldPassword('passA', $_POST['passA'], 15, 15); $field->label = '&Password'; $field->required = true; $field->saveAs = 'password'; $container->addComponent($field); $field =& new JxFieldPassword('passB', $_POST['passB'], 15, 15); $field->label = '&Verify Password'; $field->required = true; $container->addComponent($field); $this->form->addComponent($container); $container =& new JxHtmlFormContainer('PersInfo'); $container->label = 'Personalize Your Experience'; $field =& new JxFieldText('fname', $_POST['fname']); $field->label = '&First Name'; $field->required = true; $container->addComponent($field); $field =& new JxFieldText('lname', $_POST['lname']); $field->label = '&Last Name'; $field->required = true; $container->addComponent($field); $this->form->addComponent($container); // Allow plugins to add containers to the form JxPlugin::doHook('registerForm', &$this); $field =& new JxFieldSubmit('button', 'Create Account'); $this->form->addComponent($field); // validate our form's custom values if (is_array($_POST) && count($_POST)) { if ($_POST['passA'] != $_POST['passB']) { $this->form->throwError('passA', 'Passwords do not match'); } } if (!$this->form->isValid()) { $this->setData('regForm', $this->form->getForm()); } else { $this->form->exemptData = array('button', 'passB'); $this->data = $this->form->getData(); $this->data['posted'] = time(); $this->data['available'] = 1; $this->data['admin'] = 0; $this->data['userID'] = $this->user->create($this->data); if ($this->data['userID']) { $this->setData('register', $this->data); $this->templateFile = 'registerConfirm.tpl'; $session =& new JxSession(); if (!JxSession::isError($session)) { $session->create($this->data['email']); } $email =& new JxEmail($this->path . '/tpl'); if (!JxEmail::isError($email)) { $to = $this->data['email']; $subject = 'Your Account Information'; $h = array(); $h['From'] = $_SERVER['SERVER_NAME'] . ' <*****@*****.**>'; $h['Reply-To'] = $h['Return-Path'] = $h['From']; $email->template->assign('data', $this->data); $result = $email->send($to, $subject, 'registerEmail.tpl', $h); if (JxEmail::isError($result)) { $this->log->log($result->getMessage()); } } else { $this->log->log($email->getMessage()); } // Process plugins if need be JxPlugin::doHook('registerProcess', &$this); // Properly redirect JxHttp::redirect(); } else { $this->templateFile = 'registerError.tpl'; } } }
$module->templateFile = 'error.tpl'; } if ($module->user->track) { ob_start(); } $module->render(); if ($module->user->track) { $contents = ob_get_contents(); ob_end_clean(); } } } } else { // we have an invalid module die("The requested module does not exist or is in a state of error!"); } JxPlugin::doHook('indexBottom', $null); } else { if (strlen(JX_DEFAULT_MODULE)) { $go = JX_APP_PATH . '/' . JX_DEFAULT_MODULE; if (strlen(JX_DEFAULT_HANDLER)) { $go .= '/eventHandler=' . JX_DEFAULT_HANDLER; } } elseif (strlen(trim(JX_DEFAULT_URI))) { $go = JX_DEFAULT_URI; } else { die("JAX Error: No default module defined!"); } JxHttp::redirect($go); } session_write_close();