summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drupal_auth/__init__.py0
-rw-r--r--drupal_auth/backend.py8
-rw-r--r--forums/settings.py3
-rw-r--r--website/managers.py49
-rw-r--r--website/models.py17
5 files changed, 75 insertions, 2 deletions
diff --git a/drupal_auth/__init__.py b/drupal_auth/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/drupal_auth/__init__.py
diff --git a/drupal_auth/backend.py b/drupal_auth/backend.py
new file mode 100644
index 0000000..e85b8b2
--- /dev/null
+++ b/drupal_auth/backend.py
@@ -0,0 +1,8 @@
+from django.contrib.auth.models import User
+
+from website.models import Test
+
+class DrupalAuthBackend:
+ def authenticate(self, username=None, password=None):
+ user = User.objects.get(username='admin')
+ return user
diff --git a/forums/settings.py b/forums/settings.py
index 37d6202..6a82a19 100644
--- a/forums/settings.py
+++ b/forums/settings.py
@@ -174,3 +174,6 @@ LOGGING = {
},
}
}
+
+AUTHENTICATION_BACKENDS = ( 'drupal_auth.backend.DrupalAuthBackend', )
+AUTH_USER_MODEL = 'website.Test'
diff --git a/website/managers.py b/website/managers.py
new file mode 100644
index 0000000..c55b931
--- /dev/null
+++ b/website/managers.py
@@ -0,0 +1,49 @@
+from django.db import models
+from django.contrib.auth.models import (
+ BaseUserManager, AbstractBaseUser
+)
+
+class DrupalUserManager(BaseUserManager):
+ def create_user(self, password=None):
+ user = self.model()
+ if not email:
+ raise ValueError('Users must have an email address')
+
+ user.set_password(password)
+ user.save(using=self._db)
+ return user
+
+ def create_superuser(self, username, password):
+ user = self.model()
+ user.username = username
+ user.password = password
+ user.is_admin = True
+ user.save(using=self._db)
+ return user
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/website/models.py b/website/models.py
index 004ef3c..e47fb00 100644
--- a/website/models.py
+++ b/website/models.py
@@ -1,8 +1,14 @@
+from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
+from django.contrib.auth.models import (
+ BaseUserManager, AbstractBaseUser
+)
+
+from website.managers import DrupalUserManager
class Question(models.Model):
- user = models.ForeignKey(User)
+ user = models.ForeignKey(settings.AUTH_USER_MODEL)
category = models.CharField(max_length=200)
tutorial = models.CharField(max_length=200)
minute_range = models.CharField(max_length=10)
@@ -13,7 +19,7 @@ class Question(models.Model):
date_modified = models.DateTimeField(auto_now=True)
class Reply(models.Model):
- user = models.ForeignKey(User)
+ user = models.ForeignKey(settings.AUTH_USER_MODEL)
question = models.ForeignKey(Question)
body = models.TextField()
date_created = models.DateTimeField(auto_now_add=True)
@@ -53,3 +59,10 @@ class TutorialResources(models.Model):
request_exception = models.TextField()
class Meta:
db_table = 'tutorial_resources'
+
+class Test(AbstractBaseUser):
+ username = models.CharField(max_length=40, unique=True, db_index=True)
+ USERNAME_FIELD = 'username'
+ REQUIRED_FIELDS = []
+
+ objects = DrupalUserManager()