auth:django
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
auth:django [2012-08-29 22:37] – old revision restored (2012/08/29 12:07) and changed pluing data block to a list ach | auth:django [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Djangoauth ====== | ||
- | * description: | ||
- | * author | ||
- | * email : michael@oiu.ch | ||
- | * lastupdate : 2011-07-20 | ||
- | * compatible : 2011-05-25a | ||
- | * depends | ||
- | |||
- | It's an implementation which enables a nice integration with a Django [http:// | ||
- | The groups in Django can be used too. | ||
- | |||
- | Executes some python code, best to be installed on the same installation where Django lives. | ||
- | |||
- | ===== Installation ===== | ||
- | * Copy to / | ||
- | * Set the following fields in local.php | ||
- | |||
- | <code php> | ||
- | $conf[' | ||
- | $conf[' | ||
- | $conf[' | ||
- | $conf[' | ||
- | $conf[' | ||
- | </ | ||
- | |||
- | ===== Code ===== | ||
- | <code php django.class.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 { | ||
- | var $link = null; | ||
- | |||
- | /** | ||
- | * Constructor. | ||
- | * | ||
- | * Sets additional capabilities and config strings | ||
- | * @author | ||
- | */ | ||
- | function auth_django(){ | ||
- | global $conf; | ||
- | $this-> | ||
- | $this-> | ||
- | $this-> | ||
- | |||
- | // needs mysql | ||
- | if(function_exists(' | ||
- | // Connecting, selecting database | ||
- | $this-> | ||
- | or die(' | ||
- | mysql_select_db($conf[' | ||
- | } else { | ||
- | $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 | ||
- | |||
- | // Look the cookie up in the db | ||
- | $query = ' | ||
- | $result = mysql_query($query) or die(' | ||
- | $ar = mysql_fetch_row($result); | ||
- | $session_data = str_replace(" | ||
- | |||
- | // | ||
- | $python_cmd = " | ||
- | exec($python_cmd, | ||
- | |||
- | $userid = $output[0]; | ||
- | |||
- | $query = ' | ||
- | |||
- | $result2 = mysql_query($query) or die(' | ||
- | $user = mysql_fetch_row($result2); | ||
- | |||
- | $username = $user[0]; | ||
- | $userfullname = $user[1]." | ||
- | $useremail = $user[3]; | ||
- | |||
- | mysql_free_result($result); | ||
- | |||
- | // okay we're logged in - set the globals | ||
- | $groups = $this-> | ||
- | |||
- | $USERINFO[' | ||
- | $USERINFO[' | ||
- | $USERINFO[' | ||
- | $groups[0] = ' | ||
- | $USERINFO[' | ||
- | |||
- | $_SERVER[' | ||
- | |||
- | $_SESSION[DOKU_COOKIE][' | ||
- | $_SESSION[DOKU_COOKIE][' | ||
- | return true; | ||
- | } | ||
- | |||
- | return false; | ||
- | } | ||
- | |||
- | function _getUserGroups($user){ | ||
- | |||
- | // Performing SQL query | ||
- | $query = ' | ||
- | |||
- | $result = mysql_query($query) or die(' | ||
- | $a = 0; | ||
- | while($row = mysql_fetch_row($result)) { | ||
- | $groups[$a] = $row[0]; | ||
- | $a++; | ||
- | }; | ||
- | mysql_free_result($result); | ||
- | return $groups; | ||
- | } | ||
- | |||
- | function retrieveGroups($start=0, | ||
- | // Performing SQL query | ||
- | $query = ' | ||
- | |||
- | $result = mysql_query($query) or die(' | ||
- | $a = 0; | ||
- | while($row = mysql_fetch_row($result)) { | ||
- | $groups[$a] = $row[0]; | ||
- | $a++; | ||
- | }; | ||
- | mysql_free_result($result); | ||
- | return $groups; | ||
- | } | ||
- | |||
- | function __destruct() { | ||
- | mysql_close($this-> | ||
- | } | ||
- | } | ||
- | |||
- | //Setup VIM: ex: et ts=4 : | ||
- | |||
- | </ |
auth/django.1346272622.txt.gz · Last modified: 2012-08-29 22:37 by ach