auth:django
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
auth:django [2009-09-11 19:59] – created, moved from plugins HåkanS | auth:django [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Djangoauth ====== | ||
- | author | ||
- | lastupdate : 2008-08-13\\ | ||
- | compatible with DokuWiki 2008-05-05 | ||
- | It's an extremely **ugly** implementation which enables a nice integration with a Django [http:// | ||
- | |||
- | ===== Installation ===== | ||
- | * Copy to /inc/auth/ | ||
- | * Provide mysql_connect with the db contact information | ||
- | |||
- | ===== Code ===== | ||
- | <code php auth_django.php> | ||
- | <?php | ||
- | /** | ||
- | * django auth backend | ||
- | * | ||
- | * Uses external Trust mechanism to check against a django session id | ||
- | * | ||
- | * @author | ||
- | * @author | ||
- | */ | ||
- | |||
- | define(' | ||
- | define(' | ||
- | |||
- | class auth_django extends auth_basic { | ||
- | |||
- | /** | ||
- | * Constructor. | ||
- | * | ||
- | * Sets additional capabilities and config strings | ||
- | */ | ||
- | function auth_django(){ | ||
- | $this-> | ||
- | } | ||
- | |||
- | /** | ||
- | * Just checks against the django sessionid variable | ||
- | */ | ||
- | function trustExternal($user, | ||
- | global $USERINFO; | ||
- | global $conf; | ||
- | $sticky ? $sticky = true : $sticky = false; //sanity check | ||
- | |||
- | if( isset($_COOKIE[' | ||
- | |||
- | /** | ||
- | * get user info from django-database (only mysql at the moment) | ||
- | */ | ||
- | |||
- | $s_id = $_COOKIE[' | ||
- | |||
- | // Connecting, selecting database | ||
- | $link = mysql_connect(' | ||
- | or die(' | ||
- | |||
- | // Select the right table | ||
- | mysql_select_db(' | ||
- | |||
- | // Performing SQL query | ||
- | $query = ' | ||
- | |||
- | $result = mysql_query($query) or die(' | ||
- | $ar = mysql_fetch_row($result); | ||
- | |||
- | // Look for the userid, first_name, email | ||
- | ereg(" | ||
- | $userid = $data[1]; | ||
- | |||
- | $query = ' | ||
- | |||
- | $result2 = mysql_query($query) or die(' | ||
- | $user = mysql_fetch_row($result2); | ||
- | |||
- | $username = $user[0]; | ||
- | $userfullname = $user[1]; | ||
- | $useremail = $user[2]; | ||
- | |||
- | mysql_free_result($result); | ||
- | mysql_close($link); | ||
- | |||
- | |||
- | // okay we're logged in - set the globals | ||
- | $groups = $this-> | ||
- | |||
- | $USERINFO[' | ||
- | $USERINFO[' | ||
- | $USERINFO[' | ||
- | |||
- | // Hack for a standard group | ||
- | $groups[0] = ' | ||
- | |||
- | $USERINFO[' | ||
- | |||
- | $_SERVER[' | ||
- | |||
- | $_SESSION[$conf[' | ||
- | $_SESSION[$conf[' | ||
- | return true; | ||
- | } | ||
- | |||
- | return false; | ||
- | } | ||
- | |||
- | function _getUserGroups($user){ | ||
- | if(!@file_exists(AUTH_USERFILE)) return; | ||
- | |||
- | $lines = file(AUTH_USERFILE); | ||
- | foreach($lines as $line){ | ||
- | $line = preg_replace('/# | ||
- | $line = trim($line); | ||
- | if(empty($line)) continue; | ||
- | |||
- | $row = split(":", | ||
- | $groups = split(",", | ||
- | |||
- | if($user == $row[0]) return $groups; | ||
- | } | ||
- | return; | ||
- | } | ||
- | } | ||
- | </ |
auth/django.1252691973.txt.gz · Last modified: 2009-09-11 19:59 by HåkanS