ClueGun 0.2 by Agendaless Consulting (based on ClueBin by ServerZen Software).
Main page
- Paste Entry
- Author: chrism
- Date: 07/25/08 at 11:14:41
- Format: Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
from django.contrib.auth.models import User from django.contrib.auth.models import check_password class HTTPAuth: """ Login a user using http authentication """ def authenticate(self, username="foo", password="bar"): try: user = User.objects.get(username=username) except User.DoesNotExist: # Create a new user. Note that we can set password # to anything, because it won't be checked; the password # from settings.py will. user = User(username=username, password=password) user.is_staff = True user.is_superuser = True user.save() return user def get_user(self, user_id): try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None