diff options
author | Sanmugasundaram K | 2015-01-07 17:01:47 +0530 |
---|---|---|
committer | Sanmugasundaram K | 2015-01-07 17:01:47 +0530 |
commit | 9a5a239295e7aae2d211c07c9fdb117cf8252e99 (patch) | |
tree | 7a73a4b54d7d6e17b13dba45530d8903e1add635 /spoken_auth | |
parent | b665812a483c9181aec47073223d950b5b04fa1e (diff) | |
download | FOSSEE-Forum-9a5a239295e7aae2d211c07c9fdb117cf8252e99.tar.gz FOSSEE-Forum-9a5a239295e7aae2d211c07c9fdb117cf8252e99.tar.bz2 FOSSEE-Forum-9a5a239295e7aae2d211c07c9fdb117cf8252e99.zip |
drupal_auth move to spoken_auth
Diffstat (limited to 'spoken_auth')
-rw-r--r-- | spoken_auth/__init__.py | 0 | ||||
-rw-r--r-- | spoken_auth/backends.py | 25 | ||||
-rw-r--r-- | spoken_auth/managers.py | 27 | ||||
-rw-r--r-- | spoken_auth/models.py | 13 | ||||
-rw-r--r-- | spoken_auth/routers.py | 16 |
5 files changed, 81 insertions, 0 deletions
diff --git a/spoken_auth/__init__.py b/spoken_auth/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/spoken_auth/__init__.py diff --git a/spoken_auth/backends.py b/spoken_auth/backends.py new file mode 100644 index 0000000..a46ea80 --- /dev/null +++ b/spoken_auth/backends.py @@ -0,0 +1,25 @@ +import hashlib +from django.contrib.auth.models import User +from django.contrib.auth import get_user_model +from django.shortcuts import render_to_response, get_object_or_404 +from django.contrib.auth.models import update_last_login +from django.contrib.auth.signals import user_logged_in + +User = get_user_model() + +class DrupalAuthBackend(object): + def authenticate(self, username=None, password=None): + user_logged_in.disconnect(update_last_login) + try: + user = User.objects.get(username=username) + if user.check_password(password): + return user + return None + except User.DoesNotExist: + return None + + def get_user(self, user_id): + try: + return User.objects.get(pk=user_id) + except User.DoesNotExist: + return None diff --git a/spoken_auth/managers.py b/spoken_auth/managers.py new file mode 100644 index 0000000..953c867 --- /dev/null +++ b/spoken_auth/managers.py @@ -0,0 +1,27 @@ +import hashlib + +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.id = 1 + user.username= username + p = hashlib.md5() + p.update(password) + user.pass_field= p.hexdigest() + user.is_admin = True + user.save(using=self._db) + return user diff --git a/spoken_auth/models.py b/spoken_auth/models.py new file mode 100644 index 0000000..1992ed8 --- /dev/null +++ b/spoken_auth/models.py @@ -0,0 +1,13 @@ +from django.db import models +from django.contrib.auth.models import User +from django.contrib.auth.models import ( + BaseUserManager, AbstractBaseUser +) + +#from drupal_auth.managers import DrupalUserManager +class Users(AbstractBaseUser): + id = models.IntegerField(primary_key=True) + username = models.CharField(max_length=100L, unique=True) + USERNAME_FIELD = 'username' + class Meta: + db_table = 'auth_user' diff --git a/spoken_auth/routers.py b/spoken_auth/routers.py new file mode 100644 index 0000000..f2d759b --- /dev/null +++ b/spoken_auth/routers.py @@ -0,0 +1,16 @@ +class DrupalAuthRouter(object): + def db_for_read(self, model, **hints): + if model._meta.app_label == 'spoken_auth': + return 'spoken' + return 'default' + + def db_for_write(self, model, **hints): + if model._meta.app_label == 'spoken_auth': + return 'spoken' + return 'default' + + def allow_relation(self, obj1, obj2, **hints): + return True + + def allow_syncdb(self, db, model): + return True |