Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
phpbb/models.py
---------------
from django.db import models
class PhpbbUser(models.Model):
"""Model for phpBB user."""
user_id = models.IntegerField(primary_key=True)
user_active = models.BooleanField()
username = models.CharField(max_length=25)
user_password = models.CharField(max_length=32)
user_posts = models.IntegerField()
user_email = models.CharField(max_length=255)
user_website = models.CharField(max_length=100)
user_avatar_type = models.IntegerField()
user_avatar = models.CharField(max_length=250)
user_regdate_int = models.IntegerField(db_column="user_regdate")
user_lastvisit_int = models.IntegerField(db_column="user_lastvisit")
#user_sig_bbcode_uid = models.CharField(max_length=8)
#user_sig_bbcode_bitfield = models.CharField(max_length=255)
def __unicode__(self):
return self.username
def user_regdate(self):
return datetime.fromtimestamp(self.user_regdate_int)
def user_lastvisit(self):
return datetime.fromtimestamp(self.user_lastvisit_int)
class Meta:
db_table = 'phpbb_users'
ordering = ['username']
phpbb/auth.py
-------------
from django.conf import settings
from django.contrib.auth.models import User, check_password
from robosota.phpbb.models import PhpbbUser
class PhpbbBackend:
def authenticate(self, username=None, password=None):
try:
phpbbuser = PhpbbUser.objects.get(username=username)
except:
return None
pwd_valid = check_password(password, 'md5$$'+phpbbuser.user_password)
if not pwd_valid:
return None
try:
user = User.objects.get(username=username)
except User.DoesNotExist:
user = User(username=username, password='phpbb password')
user.save()
return user
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
settinsgs.py
------------
AUTHENTICATION_BACKENDS = (
'robosota.phpbb.auth.PhpbbBackend',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment