Exemplo n.º 1
0
 function User_xe17($id = '')
 {
     global $Config;
     parent::WikiUser($id);
     $cookie_id = $this->id != 'Anonymous' ? $this->id : '';
     // set xe_root_dir config option
     $xe_root_dir = !empty($Config['xe_root_dir']) ? $Config['xe_root_dir'] : dirname(__FILE__) . '/../../../xe';
     // default xe_root_dir is 'xe' subdirectory of the parent dir of the moniwiki
     $sessid = session_name();
     // PHPSESSID
     // set the session_id() using saved cookie
     if (isset($_COOKIE[$sessid])) {
         session_id($_COOKIE[$sessid]);
     }
     // do not use cookies for varnish cache server
     ini_set("session.use_cookies", 0);
     session_cache_limiter('');
     // Cache-Control manually for varnish cache
     session_start();
     // is it a valid user ?
     $udb = new UserDB($Config);
     $user = $udb->getUser($cookie_id);
     $update = false;
     if (!empty($cookie_id)) {
         // not found
         if ($user->id == 'Anonymous') {
             $this->setID('Anonymous');
             $update = true;
             $cookie_id = '';
         } else {
             // check ticket
             $ticket = getTicket($user->id, $_SERVER['REMOTE_ADDR']);
             if ($this->ticket != $ticket) {
                 // not a valid user
                 $this->ticket = '';
                 $this->setID('Anonymous');
                 $update = true;
                 //$cookie_id = '';
             } else {
                 // OK good user
                 $this->setID($cookie_id);
                 $id = $cookie_id;
                 $this->nick = $user->info['nick'];
                 $this->tz_offset = $user->info['tz_offset'];
                 $this->info = $user->info;
                 $this->ticket = $ticket;
             }
         }
     } else {
         // empty cookie
         $update = true;
     }
     if ($update && !empty($_SESSION['is_logged'])) {
         // init XE17, XE18
         define('__XE__', true);
         require_once $xe_root_dir . "/config/config.inc.php";
         $context =& Context::getInstance();
         $this->xe_context_init($context);
         // simplified init context method
         // $context->init(); // slow slow
         $oMemberModel =& getModel('member');
         $oMemberController =& getController('member');
         $oMemberController->setSessionInfo();
         $member = new memberModel();
         $xeinfo = $member->getLoggedInfo();
         $id = $xeinfo->user_id;
         $user = $udb->getUser($id);
         // get user info again
         // not a registered user ?
         if ($user->id == 'Anonymous' || $update || empty($user->info['nick'])) {
             // check groups
             $groups = array_keys($xeinfo->group_list);
             $wikigroups = array();
             $group_ok = $xeinfo->is_admin == 'Y' ? true : false;
             if (!empty($Config['xe_allowed_groups'])) {
                 $allowed_groups = $Config['xe_allowed_groups'];
                 for ($i = 0; $i < sizeof($groups); $i++) {
                     if (isset($allowed_groups[$groups[$i]])) {
                         $group_ok = true;
                         $groupname = $allowed_groups[$groups[$i]];
                         if (!empty($groupname)) {
                             $wikigroups[] = $groupname;
                         }
                     }
                 }
             } else {
                 $group_ok = true;
             }
             if ($group_ok) {
                 if (!empty($wikigroups)) {
                     $this->groups = $wikigroups;
                     $user->info['groups'] = implode(',', $wikigroups);
                     $this->info['groups'] = $user->info['groups'];
                 } else {
                     if (!empty($this->info['groups'])) {
                         $user->info['groups'] = '@User';
                         $this->info['groups'] = $user->info['groups'];
                     }
                 }
                 $this->setID($id);
                 // not found case
                 $this->info = $user->info;
                 // already registered case
                 $ticket = getTicket($id, $_SERVER['REMOTE_ADDR']);
                 // get ticket
                 if ($this->nick != $xeinfo->nick_name) {
                     $this->nick = $xeinfo->nick_name;
                     $this->info['nick'] = $xeinfo->nick_name;
                 }
                 if ($this->info['email'] == '') {
                     $this->info['email'] = $xeinfo->email_address;
                 }
                 $this->info['tz_offset'] = $this->tz_offset;
                 $this->ticket = $ticket;
             } else {
                 if (!empty($cookie_id)) {
                     header($this->unsetCookie());
                 }
                 $this->setID('Anonymous');
                 $id = 'Anonymous';
             }
         }
     } else {
         // not logged in
         if (empty($_SESSION['is_logged'])) {
             if (!empty($cookie_id)) {
                 header($this->unsetCookie());
             }
             $this->setID('Anonymous');
             $id = 'Anonymous';
         }
     }
     if ($update || !empty($id) and $id != 'Anonymous') {
         if ($cookie_id != $id) {
             header($this->setCookie());
         }
     }
     if ($update || !$udb->_exists($id)) {
         if (!$udb->_exists($id)) {
             if (!empty($Config['use_agreement']) && empty($this->info['join_agreement'])) {
                 $this->info['join_agreement'] = 'disagree';
             }
         }
         // automatically save/register user
         $dummy = $udb->saveUser($this);
     }
 }