=== added file 'doc/django.rst'
--- doc/django.rst	1970-01-01 00:00:00 +0000
+++ doc/django.rst	2009-02-23 13:51:29 +0000
@@ -0,0 +1,33 @@
+====================================
+Fedora Django Authentication Backend
+====================================
+:Authors: Ignacio Vazquez-Abrams
+:Date: 23 Feb 2009
+:For Version: 0.3.x
+
+The django.auth package provides an authentication backend for Django
+projects.
+
+------------------
+fedora.django.auth
+------------------
+
+As FAS users are authenticated they are added to
+:class:`~fedora.django.auth.models.FasUser`. FAS groups are added to
+:class:`~django.contrib.auth.models.Group` both during ``syncdb`` and when
+a user is authenticated.
+
+Integrating into a Django Project
+=================================
+
+Add the following lines to the project's ``settings.py``:
+
+    AUTHENTICATION_BACKENDS = (
+        'fedora.django.auth.backends.FasBackend',
+    )
+
+    FAS_USERNAME = '<username>'
+    FAS_PASSWORD = '<password>'
+    FAS_USERAGENT = '<user agent>'
+    
+Add ``fedora.django.auth`` to ``INSTALLED_APPS``.

=== added directory 'fedora/django'
=== added file 'fedora/django/__init__.py'
--- fedora/django/__init__.py	1970-01-01 00:00:00 +0000
+++ fedora/django/__init__.py	2009-02-23 12:58:40 +0000
@@ -0,0 +1,12 @@
+from fedora.client import AccountSystem
+
+from django.conf import settings
+
+connection = None
+
+def _connect():
+    global connection
+    connection = AccountSystem(username=settings.FAS_USERNAME,
+        password=settings.FAS_PASSWORD, useragent=settings.FAS_USERAGENT)
+
+_connect()

=== added directory 'fedora/django/auth'
=== added file 'fedora/django/auth/__init__.py'
=== added file 'fedora/django/auth/backends.py'
--- fedora/django/auth/backends.py	1970-01-01 00:00:00 +0000
+++ fedora/django/auth/backends.py	2009-02-23 13:34:14 +0000
@@ -0,0 +1,16 @@
+from fedora.django import connection
+from fedora.django.auth.models import FasUser
+
+from django.db.models.signals import post_syncdb
+
+class FasBackend:
+    def authenticate(self, username=None, password=None):
+        if connection.verify_password(username, password):
+            userinfo = connection.person_by_username(username)
+            return FasUser.objects.user_from_fas(userinfo)
+
+    def get_user(self, userid):
+        try:
+            return FasUser.objects.get(id=userid)
+        except FasUser.DoesNotExist:
+            return

=== added directory 'fedora/django/auth/management'
=== added file 'fedora/django/auth/management/__init__.py'
--- fedora/django/auth/management/__init__.py	1970-01-01 00:00:00 +0000
+++ fedora/django/auth/management/__init__.py	2009-02-23 13:35:41 +0000
@@ -0,0 +1,5 @@
+from fedora.django.auth import models
+
+from django.db.models.signals import post_syncdb
+
+post_syncdb.connect(models._syncdb_handler, sender=models)

=== added file 'fedora/django/auth/models.py'
--- fedora/django/auth/models.py	1970-01-01 00:00:00 +0000
+++ fedora/django/auth/models.py	2009-02-23 13:52:38 +0000
@@ -0,0 +1,60 @@
+from fedora.django import connection
+
+import django.contrib.auth.models as authmodels
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+# Map FAS user elements to model attributes
+_fasmap = {
+    'id': 'id',
+    'username': 'username',
+    'email': 'email',
+    'human_name': 'name',
+}
+
+def _new_group(group):
+    try:
+        g = authmodels.Group.objects.get(id=group['id'])
+    except authmodels.Group.DoesNotExist:
+        g = authmodels.Group(id=group['id'])
+    g.name = group['name']
+    g.save()
+    return g
+
+def _syncdb_handler(sender, **kwargs):
+    # Import FAS groups
+    if kwargs['verbosity'] > 0:
+        print 'Loading FAS groups...'
+    gl = connection.send_request('group/list',
+        req_params={'tg_format': 'json'})
+    groups = gl['groups']
+    for group in groups:
+        _new_group(group)
+
+class FasUserManager(authmodels.UserManager):
+    def user_from_fas(self, user):
+        """
+        Creates a user in the table based on the structure returned
+        by FAS
+        """
+        d = {}
+        for k, v in _fasmap.iteritems():
+            d[v] = user[k]
+        u = FasUser(**d)
+        u.set_unusable_password()
+        u.is_active = user['status'] == 'active'
+#        u.is_superuser = 
+        u.save()
+        for group in user['approved_memberships']:
+            g = _new_group(group)
+            u.groups.add(g)
+        u.save()
+        return u
+
+class FasUser(authmodels.User):
+    name = models.CharField(_('name'), max_length=80, blank=True)
+
+    objects = FasUserManager()
+
+    def get_full_name(self):
+        return name.strip()

