Ticket #689: httpauth.py

File httpauth.py, 1.2 KB (added by ian@…, 18 years ago)

middleware version of same idea

Line 
1from django.parts.auth import anonymoususers
2from django.models.auth import users, User
3import md5
4import datetime
5class HttpAuth:
6    """
7    Grabs what the webserver thinks is the logged on user id,
8    and use that instead, creating the record if it doesn't exist in the table.
9
10    There are currently three problems with this at the moment.
11     * It doesn't update the last-login
12     * It doesn't update the session cookie
13     * It has no idea what the email address is
14    """
15    def process_request(self,request):
16        "gets REMOTE_USER and sets the userid based on that"
17        if request.META['REMOTE_USER']:
18            user_id = request.META['REMOTE_USER']#+'_remote'
19            try:
20                user = users.get_object(username__exact=user_id)
21            except (users.UserDoesNotExist):
22                now = datetime.datetime.now()
23                user = User(None, user_id,'','', 
24                        user_id+'@example.com',
25                        'XXno_passwordXX',
26                        False,True,False,now,now)
27                user.save()
28        else:
29            user = anonymoususers.AnonymousUser()
30        request.user= user
31        return None
Back to Top