Changeset b90e90b


Ignore:
Timestamp:
Dec 19, 2011, 8:30:04 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
5543d51
Parents:
776830d
git-author:
Alex Dehnert <adehnert@…> (12/18/11 00:49:59)
git-committer:
Alex Dehnert <adehnert@…> (12/19/11 20:30:04)
Message:

Function to create an MIT user with LDAP data

This adds a function get_or_create_mit_user. As with the "get_or_create"
methods on managers, this returns an object satisfying some conditions,
creating it if necessary. In this case, we return a User object that's
populated using data from MIT's LDAP. If the user does not exist and
cannot be found in LDAP, we raise an exception.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/mit/__init__.py

    r2b38cb9 rb90e90b  
    5656        return user
    5757
     58def get_or_create_mit_user(username, ):
     59    """
     60    Given an MIT username, return a Django user object for them.
     61    If necessary, create (and save) the Django user for them.
     62    If the MIT user doesn't exist, raises ValueError.
     63    """
     64    user, created = auth.models.User.objects.get_or_create(username=username, )
     65    if created:
     66        backend = ScriptsRemoteUserBackend()
     67        # Raises ValueError if the user doesn't exist
     68        try:
     69            return backend.configure_user(user), created
     70        except ValueError:
     71            user.delete()
     72            raise
     73    else:
     74        return user, created
     75
    5876def scripts_login(request, **kwargs):
    5977    host = request.META['HTTP_HOST'].split(':')[0]
Note: See TracChangeset for help on using the changeset viewer.