XOOPS Docs - kernel
[ class tree: kernel ] [ index: kernel ] [ all elements ]

Source for file auth_provisionning.php

Documentation is available at auth_provisionning.php

  1. <?php
  2. // $Id: auth_provisionning.php 733 2006-09-11 20:42:29Z pemen $
  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.  
  37.     var $_auth_instance;
  38.     
  39.     function &getInstance(&$auth_instance)
  40.     {
  41.         static $provis_instance;                
  42.         if (!isset($provis_instance)) {
  43.             $provis_instance new XoopsAuthProvisionning($auth_instance);
  44.         }
  45.         return $provis_instance;
  46.     }
  47.  
  48.     /**
  49.      * Authentication Service constructor
  50.      */
  51.     function XoopsAuthProvisionning (&$auth_instance{
  52.         $this->_auth_instance = &$auth_instance;        
  53.         $config_handler =xoops_gethandler('config');    
  54.         $config =$config_handler->getConfigsByCat(XOOPS_CONF_AUTH);
  55.         foreach ($config as $key => $val{
  56.             $this->$key $val;
  57.         }
  58.         $config_gen =$config_handler->getConfigsByCat(XOOPS_CONF);
  59.         $this->default_TZ $config_gen['default_TZ'];
  60.         $this->theme_set $config_gen['theme_set'];
  61.         $this->com_mode $config_gen['com_mode'];
  62.         $this->com_order $config_gen['com_order'];        
  63.     }
  64.  
  65.     /**
  66.      *  Return a Xoops User Object
  67.      *
  68.      * @return XoopsUser or false
  69.      */    
  70.     function getXoopsUser($uname{
  71.         $member_handler =xoops_gethandler('member');
  72.         $criteria new Criteria('uname'$uname);
  73.         $getuser $member_handler->getUsers($criteria);
  74.         if (count($getuser== 1)
  75.             return $getuser[0];
  76.         else return false;        
  77.     }
  78.     
  79.     /**
  80.      *  Launch the synchronisation process
  81.      *
  82.      * @return bool 
  83.      */        
  84.     function sync($datas$uname$pwd null{
  85.         $xoopsUser $this->getXoopsUser($uname);        
  86.         if (!$xoopsUser// Xoops User Database not exists
  87.             if ($this->ldap_provisionning
  88.                 $xoopsUser $this->add($datas$uname$pwd);
  89.             else $this->_auth_instance->setErrors(0sprintf(_AUTH_LDAP_XOOPS_USER_NOTFOUND$uname));
  90.         else // Xoops User Database exists
  91.             if ($this->ldap_provisionning && $this->ldap_provisionning_upd
  92.                 $xoopsUser $this->change($xoopsUser$datas$uname$pwd);
  93.             }
  94.         }
  95.         return $xoopsUser;
  96.     }
  97.  
  98.     /**
  99.      *  Add a new user to the system
  100.      *
  101.      * @return bool 
  102.      */        
  103.     function add($datas$uname$pwd null{
  104.         $ret false;
  105.         $member_handler =xoops_gethandler('member');
  106.         // Create XOOPS Database User
  107.         $newuser $member_handler->createUser();
  108.         $newuser->setVar('uname'$uname);
  109.         $newuser->setVar('pass'md5(stripslashes($pwd)));
  110.         //$newuser->setVar('name', utf8_decode($datas[$this->ldap_givenname_attr][0]) . ' ' . utf8_decode($datas[$this->ldap_surname_attr][0]));
  111.         //$newuser->setVar('email', $datas[$this->ldap_mail_attr][0]);
  112.         $newuser->setVar('rank'0);
  113.         $newuser->setVar('level'1);
  114.         $newuser->setVar('timezone_offset'$this->default_TZ);
  115.         $newuser->setVar('theme',     $this->theme_set);
  116.         $newuser->setVar('umode',     $this->com_mode);
  117.         $newuser->setVar('uorder',     $this->com_order);
  118.         $tab_mapping explode('|'$this->ldap_field_mapping);
  119.         foreach ($tab_mapping as $mapping{
  120.             $fields explode('='trim($mapping));
  121.             if ($fields[0&& $fields[1])
  122.                 $newuser->setVar(trim($fields[0])utf8_decode($datas[trim($fields[1])][0]));
  123.         }        
  124.         if ($member_handler->insertUser($newuser)) {
  125.             foreach ($this->ldap_provisionning_group as $groupid)
  126.                 $member_handler->addUserToGroup($groupid$newuser->getVar('uid'));
  127.             $newuser->unsetNew();
  128.             return $newuser;
  129.         else redirect_header(XOOPS_URL.'/user.php'5$newuser->getHtmlErrors());         
  130.         return $ret;    
  131.     }
  132.     
  133.     /**
  134.      *  Modify user information
  135.      *
  136.      * @return bool 
  137.      */        
  138.     function change(&$xoopsUser$datas$uname$pwd null{    
  139.         $ret false;
  140.         $member_handler =xoops_gethandler('member');
  141.         $xoopsUser->setVar('pass'md5(stripslashes($pwd)));
  142.         $tab_mapping explode('|'$this->ldap_field_mapping);
  143.         foreach ($tab_mapping as $mapping{
  144.             $fields explode('='trim($mapping));
  145.             if ($fields[0&& $fields[1])
  146.                 $xoopsUser->setVar(trim($fields[0])utf8_decode($datas[trim($fields[1])][0]));
  147.         }
  148.         if ($member_handler->insertUser($xoopsUser)) {
  149.             return $xoopsUser;
  150.         else redirect_header(XOOPS_URL.'/user.php'5$xoopsUser->getHtmlErrors());         
  151.         return $ret;
  152.     }
  153.  
  154.     /**
  155.      *  Modify a user
  156.      *
  157.      * @return bool 
  158.      */        
  159.     function delete({
  160.     }
  161.  
  162.     /**
  163.      *  Suspend a user
  164.      *
  165.      * @return bool 
  166.      */        
  167.     function suspend({
  168.     }
  169.  
  170.     /**
  171.      *  Restore a user
  172.      *
  173.      * @return bool 
  174.      */        
  175.     function restore({
  176.     }
  177.  
  178.     /**
  179.      *  Add a new user to the system
  180.      *
  181.      * @return bool 
  182.      */        
  183.     function resetpwd({
  184.     }
  185.     
  186.     
  187. // end class
  188.  
  189. ?>

XOOPS Docs generated by phpDocumentor