示例#1
0
文件: logout.php 项目: joestump/jax
 function __default()
 {
     $session = new JxSession();
     if (!JxSession::isError($session)) {
         $session->destroy();
         JxHttp::redirect();
     }
 }
示例#2
0
文件: login.php 项目: joestump/jax
 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();
         }
     }
 }
示例#3
0
文件: user.php 项目: joestump/jax
 function &singleton()
 {
     static $user = null;
     if ($user === null) {
         if (JxSession::isValid() && isset($_COOKIE['jax_userID']) && is_numeric($_COOKIE['jax_userID'])) {
             $user =& new JxUser((int) $_COOKIE['jax_userID']);
         } else {
             $user =& new JxUser(0);
         }
     }
     return $user;
 }
示例#4
0
文件: register.php 项目: joestump/jax
 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';
         }
     }
 }
示例#5
0
 /**
  * JxAuthUser
  *
  * @author Joe Stump <*****@*****.**>
  * @access public
  * @return void
  * @see JxSession, JxUser
  */
 function authenticate()
 {
     return JxSession::isValid();
 }