[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/auth/extauth/shibboleth/ -> shibboleth.lib.php (source)

   1  <?php // $Id: shibboleth.lib.php,v 1.1.4.3 2007/08/03 07:58:44 stredani Exp $
   2  if ( count( get_included_files() ) == 1 ) die( '---' );
   3  
   4  /**
   5   * Claroline Shibboleth / Switch AAI
   6   *
   7   * Library and Configuration
   8   *
   9   * @version 0.4
  10   *
  11   * @author Daniel Streiff <daniel.streiff@fh-htwchur.ch>
  12   */
  13  
  14  /**
  15   * Set Shibboleth server attributes manually
  16   *
  17   * @author Daniel Streiff <daniel.streiff@fh-htwchur.ch>
  18   * @return
  19   */
  20  
  21  function setShibbolethAttributes()
  22  {
  23      global $shibboleth_conf ;
  24  
  25      // set server attributes
  26      foreach($shibboleth_conf as $key => $value)
  27      {
  28          $_SERVER[$key] = $value;
  29      }
  30  
  31  }
  32  
  33  /**
  34   * Check if a username is already used
  35   *
  36   * @author Daniel Streiff <daniel.streiff@fh-htwchur.ch>
  37   * @param string $username
  38   * @return boolean
  39   */
  40  
  41  function shibbolethUsernameExists($username)
  42  {
  43      global $tbl_user;
  44      global $shibbolethAuthSource;
  45  
  46      // unique for all authSources
  47      $sql = 'SELECT count(*)
  48              FROM `' . $tbl_user . '`
  49              WHERE
  50               username = "' . addslashes($username) . '"'
  51           ;
  52      $result = claro_sql_query($sql);
  53      $row = mysql_fetch_array($result);
  54  
  55      if ( $row[0] == 0 )
  56      {
  57          return false;
  58      }
  59      else
  60      {
  61          return true;
  62      }
  63  }
  64  
  65  /**
  66   * Generate a unique username
  67   *
  68   * @author Daniel Streiff <daniel.streiff@fh-htwchur.ch>
  69   * @param string $lastname
  70   * @param string $firstname
  71   * @return string
  72   */
  73  
  74  function shibbolethUniqueUsername($lastname, $firstname, $lnLen = 10, $fnLen = 10)
  75  {
  76      $maxLen = 20;
  77      $lastname  = substr(utf8_decode($lastname),  0, $lnLen);
  78      $firstname = substr(utf8_decode($firstname), 0, $fnLen);
  79      $shibbolethUsername = $lastname . $firstname;
  80      $i = 0;
  81      while (shibbolethUsernameExists($shibbolethUsername))
  82      {
  83          $i++;
  84          $shibbolethUsername = substr($lastname . $firstname, 0, $maxLen - strlen($i)) . $i;
  85      }
  86      return $shibbolethUsername;
  87  }
  88  
  89  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics