home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / xoops-2.0.18.1.exe / xoops-2.0.18.1 / htdocs / class / auth / auth_provisionning.php < prev    next >
Encoding:
PHP Script  |  2007-09-09  |  6.8 KB  |  191 lines

  1. <?php
  2. // $Id: auth_provisionning.php 1029 2007-09-09 03:49:25Z phppp $
  3. //  ------------------------------------------------------------------------ //
  4. //                XOOPS - PHP Content Management System                      //
  5. //                    Copyright (c) 2000 XOOPS.org                           //
  6. //                       <http://www.xoops.org/>                             //
  7. //  ------------------------------------------------------------------------ //
  8. //  This program is free software; you can redistribute it and/or modify     //
  9. //  it under the terms of the GNU General Public License as published by     //
  10. //  the Free Software Foundation; either version 2 of the License, or        //
  11. //  (at your option) any later version.                                      //
  12. //                                                                           //
  13. //  You may not change or alter any portion of this comment or credits       //
  14. //  of supporting developers from this source code or any supporting         //
  15. //  source code which is considered copyrighted (c) material of the          //
  16. //  original comment or credit authors.                                      //
  17. //                                                                           //
  18. //  This program is distributed in the hope that it will be useful,          //
  19. //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
  20. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
  21. //  GNU General Public License for more details.                             //
  22. //                                                                           //
  23. //  You should have received a copy of the GNU General Public License        //
  24. //  along with this program; if not, write to the Free Software              //
  25. //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
  26. //  ------------------------------------------------------------------------ //
  27. /**
  28.  * @package     kernel
  29.  * @subpackage  auth
  30.  * @description    Authentification provisionning class. This class is responsible to
  31.  * provide synchronisation method to Xoops User Database
  32.  * 
  33.  * @author        Pierre-Eric MENUET    <pemphp@free.fr>
  34.  * @copyright    copyright (c) 2000-2003 XOOPS.org
  35.  */
  36. class XoopsAuthProvisionning {
  37.  
  38.     var $_auth_instance;
  39.     
  40.     function &getInstance(&$auth_instance)
  41.     {
  42.         static $provis_instance;                
  43.         if (!isset($provis_instance)) {
  44.             $provis_instance = new XoopsAuthProvisionning($auth_instance);
  45.         }
  46.         return $provis_instance;
  47.     }
  48.  
  49.     /**
  50.      * Authentication Service constructor
  51.      */
  52.     function XoopsAuthProvisionning (&$auth_instance) {
  53.         $this->_auth_instance = &$auth_instance;        
  54.         $config_handler =& xoops_gethandler('config');    
  55.         $config =& $config_handler->getConfigsByCat(XOOPS_CONF_AUTH);
  56.         foreach ($config as $key => $val) {
  57.             $this->$key = $val;
  58.         }
  59.         $config_gen =& $config_handler->getConfigsByCat(XOOPS_CONF);
  60.         $this->default_TZ = $config_gen['default_TZ'];
  61.         $this->theme_set = $config_gen['theme_set'];
  62.         $this->com_mode = $config_gen['com_mode'];
  63.         $this->com_order = $config_gen['com_order'];        
  64.     }
  65.  
  66.     /**
  67.      *  Return a Xoops User Object 
  68.      *
  69.      * @return XoopsUser or false
  70.      */    
  71.     function getXoopsUser($uname) {
  72.         $member_handler =& xoops_gethandler('member');
  73.         $criteria = new Criteria('uname', $uname);
  74.         $getuser = $member_handler->getUsers($criteria);
  75.         if (count($getuser) == 1)
  76.             return $getuser[0];
  77.         else return false;        
  78.     }
  79.     
  80.     /**
  81.      *  Launch the synchronisation process 
  82.      *
  83.      * @return bool
  84.      */        
  85.     function sync($datas, $uname, $pwd = null) {
  86.         $xoopsUser = $this->getXoopsUser($uname);        
  87.         if (!$xoopsUser) { // Xoops User Database not exists
  88.             if ($this->ldap_provisionning) { 
  89.                 $xoopsUser = $this->add($datas, $uname, $pwd);
  90.             } else $this->_auth_instance->setErrors(0, sprintf(_AUTH_LDAP_XOOPS_USER_NOTFOUND, $uname));
  91.         } else { // Xoops User Database exists
  92.             if ($this->ldap_provisionning && $this->ldap_provisionning_upd) { 
  93.                 $xoopsUser = $this->change($xoopsUser, $datas, $uname, $pwd);
  94.             }
  95.         }
  96.         return $xoopsUser;
  97.     }
  98.  
  99.     /**
  100.      *  Add a new user to the system
  101.      *
  102.      * @return bool
  103.      */        
  104.     function add($datas, $uname, $pwd = null) {
  105.         $ret = false;
  106.         $member_handler =& xoops_gethandler('member');
  107.         // Create XOOPS Database User
  108.         $newuser = $member_handler->createUser();
  109.         $newuser->setVar('uname', $uname);
  110.         $newuser->setVar('pass', md5(stripslashes($pwd)));
  111.         //$newuser->setVar('name', utf8_decode($datas[$this->ldap_givenname_attr][0]) . ' ' . utf8_decode($datas[$this->ldap_surname_attr][0]));
  112.         //$newuser->setVar('email', $datas[$this->ldap_mail_attr][0]);
  113.         $newuser->setVar('rank', 0);
  114.         $newuser->setVar('level', 1);
  115.         $newuser->setVar('timezone_offset', $this->default_TZ);
  116.         $newuser->setVar('theme',     $this->theme_set);
  117.         $newuser->setVar('umode',     $this->com_mode);
  118.         $newuser->setVar('uorder',     $this->com_order);
  119.         $tab_mapping = explode('|', $this->ldap_field_mapping);
  120.         foreach ($tab_mapping as $mapping) {
  121.             $fields = explode('=', trim($mapping));
  122.             if ($fields[0] && $fields[1])
  123.                 $newuser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
  124.         }        
  125.         if ($member_handler->insertUser($newuser)) {
  126.             foreach ($this->ldap_provisionning_group as $groupid)
  127.                 $member_handler->addUserToGroup($groupid, $newuser->getVar('uid'));
  128.             $newuser->unsetNew();
  129.             return $newuser;
  130.         } else redirect_header(XOOPS_URL.'/user.php', 5, $newuser->getHtmlErrors());         
  131.         return $ret;    
  132.     }
  133.     
  134.     /**
  135.      *  Modify user information
  136.      *
  137.      * @return bool
  138.      */        
  139.     function change(&$xoopsUser, $datas, $uname, $pwd = null) {    
  140.         $ret = false;
  141.         $member_handler =& xoops_gethandler('member');
  142.         $xoopsUser->setVar('pass', md5(stripslashes($pwd)));
  143.         $tab_mapping = explode('|', $this->ldap_field_mapping);
  144.         foreach ($tab_mapping as $mapping) {
  145.             $fields = explode('=', trim($mapping));
  146.             if ($fields[0] && $fields[1])
  147.                 $xoopsUser->setVar(trim($fields[0]), utf8_decode($datas[trim($fields[1])][0]));
  148.         }
  149.         if ($member_handler->insertUser($xoopsUser)) {
  150.             return $xoopsUser;
  151.         } else redirect_header(XOOPS_URL.'/user.php', 5, $xoopsUser->getHtmlErrors());         
  152.         return $ret;
  153.     }
  154.  
  155.     /**
  156.      *  Modify a user
  157.      *
  158.      * @return bool
  159.      */        
  160.     function delete() {
  161.     }
  162.  
  163.     /**
  164.      *  Suspend a user
  165.      *
  166.      * @return bool
  167.      */        
  168.     function suspend() {
  169.     }
  170.  
  171.     /**
  172.      *  Restore a user
  173.      *
  174.      * @return bool
  175.      */        
  176.     function restore() {
  177.     }
  178.  
  179.     /**
  180.      *  Add a new user to the system
  181.      *
  182.      * @return bool
  183.      */        
  184.     function resetpwd() {
  185.     }
  186.     
  187.     
  188. } // end class
  189.  
  190. ?>
  191.