factorize code and add group info for external sites (especially for xnet auth in...
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 18 Feb 2007 00:22:35 +0000 (00:22 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sun, 18 Feb 2007 00:22:35 +0000 (00:22 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1507 839d8a87-29fc-0310-9880-83ba4fa771e5

modules/auth/auth.inc.php

index 1a95ebf..208c691 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-/* cree le champs "auth" renvoye au Groupe X */
-function gpex_make_auth($chlg, $privkey, $datafields) {
-    $fieldarr = explode(",",$datafields);
+function gpex_make($chlg, $privkey, $datafields)
+{
     $tohash   = "1$chlg$privkey";
+    $params   = "";
+    $fieldarr = explode(",",$datafields);
 
     $res = XDB::query("SELECT matricule, matricule_ax, promo,
                                         promo_sortie, flags, deces, nom,
@@ -46,42 +47,31 @@ function gpex_make_auth($chlg, $privkey, $datafields) {
                                         S::v('uid'));
             $min_username = $res->fetchOneCell();
             $tohash      .= $min_username;
+            $params      .= "&$val=".$min_username;
+        } else if ($val == 'grpauth' && isset($_GET['group'])) {
+               $res = XDB::query("SELECT perms FROM groupex.membres
+                               INNER JOIN groupex.asso ON(id = asso_id) 
+                               WHERE uid = {?} AND diminutif = {?}", S::v('uid'), $_GET['group']);
+                       $perms = $res->fetchOneCell();
+                       $tohash .= $perms;
+                       $params .= "&$val=".$perms;
         }
     }
     $tohash .= "1";
-    return md5($tohash);
+    $auth = md5($tohash);
+    return array($auth, "&auth=".$auth.$params);
+}
+
+/* cree le champs "auth" renvoye au Groupe X */
+function gpex_make_auth($chlg, $privkey, $datafields) {
+       list ($auth, $param) = gpex_make($chlg, $privkey, $datafields);
+       return $auth;
 }
 
 /* cree les parametres de l'URL de retour avec les champs demandes */
 function gpex_make_params($chlg, $privkey, $datafields) {
-    $params   = "&auth=".gpex_make_auth($chlg, $privkey, $datafields);
-
-    $res = XDB::query("SELECT matricule, matricule_ax, promo,
-                              promo_sortie, flags, deces, nom,
-                              prenom, nationalite, section,
-                              naissance
-                         FROM auth_user_md5 WHERE user_id = {?}",
-                      S::v('uid'));
-    $personnal_data = $res->fetchOneAssoc();
-
-    $fieldarr = explode(",",$datafields);
-
-    foreach ($fieldarr as $val) {
-        if (S::has($val)) {
-            $tohash .= S::v($val);
-            $params .= "&$val=".S::v($val);
-        } else if (isset($personnal_data[$val])) {
-            $tohash .= $personnal_data[$val];
-            $params .= "&$val=".$personnal_data[$val];
-        } else if ($val == 'username') {
-            $res = XDB::query("SELECT alias FROM aliases 
-                                          WHERE id = {?} AND FIND_IN_SET('bestalias', flags)",
-                                        S::v('uid'));
-            $min_username = $res->fetchOneCell();
-            $params      .= "&$val=".$min_username;
-        }
-    }
-    return $params;
+       list ($auth, $param) = gpex_make($chlg, $privkey, $datafields);
+       return $param;
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: