fc5a689307242579738e01fab0d69e427c3c28e1
[atutor.git] / mods / wiki / plugins / auth / userdb_xprofile.php
1 <?php
2 /*
3    Allows access using XML User Profiles (XUP/XProfile). Requires $_SESSION support.
4 */
5
6 #-- init hack (runs slow without)
7 if (!constant("SESSION_ID") && !session_id()) { 
8    session_start();
9 }
10
11
12 $ewiki_plugins["auth_userdb"][] = "ewiki_auth_userdb_xprofile";
13
14 function ewiki_auth_userdb_xprofile($username, $password) {
15    global $ewiki_author;
16    
17    #-- already logged in
18    if ($_SESSION["xprofile"]) {
19       $ewiki_author = $_SESSION["ewiki_author"];
20       return($true);
21    }
22
23    #-- fetch profile
24    $xpro = new xprofile($username);  // URL or email-like shortcut
25    if ($xpro->control) {
26   
27       #-- validate
28       if ($xpro->login() ) {
29       
30          #-- save data
31          $_SESSION["ewiki_author"] = $ewiki_author = $xpro->info["nickname"];
32          $_SESSION["xprofile"] = $xpro->url;
33       
34          return(true);
35       }
36       else {
37          // misuse (already logged by XProfile manager)
38          ewiki_log("userdb_xprofile: wrong password '...' for remote account on '$username'", 1);
39       }
40    }
41
42    return(false);   
43 }
44
45 ?>