diff options
Diffstat (limited to 'testapp/myauthentication')
-rw-r--r-- | testapp/myauthentication/README | 2 | ||||
-rw-r--r-- | testapp/myauthentication/backend.py | 25 | ||||
-rw-r--r-- | testapp/myauthentication/models_spoken_tutorial.py (renamed from testapp/myauthentication/models_spoken.py) | 2 | ||||
-rw-r--r-- | testapp/myauthentication/router.py | 2 | ||||
-rw-r--r-- | testapp/myauthentication/tests.py | 17 |
5 files changed, 19 insertions, 29 deletions
diff --git a/testapp/myauthentication/README b/testapp/myauthentication/README index 6d1a7b4..4aef3c5 100644 --- a/testapp/myauthentication/README +++ b/testapp/myauthentication/README @@ -3,7 +3,7 @@ To use authentication from external source, follow the instructions given below: 1. In settings.py, Uncomment AUTHENTICATION_BACKENDS = ('myauthentication.backend.MyBackend',) Uncomment AUTHENTICATION_BACKENDS = ('myauthentication.backend.MyBackend',) - Enter database name, username and password for the spoken database. + Enter database name, username and password for the spoken tutorial database. 2. From login.html template comment 'New User? Sign-Up' link. This is to be done so that user will register only from external diff --git a/testapp/myauthentication/backend.py b/testapp/myauthentication/backend.py index d82f11a..721fe54 100644 --- a/testapp/myauthentication/backend.py +++ b/testapp/myauthentication/backend.py @@ -1,6 +1,7 @@ import hashlib from django.contrib.auth.models import User, check_password -from models_spoken import MdlUser +from models_spoken_tutorial import MoodleUser + class MyBackend: supports_object_permissions = False @@ -14,24 +15,24 @@ class MyBackend: and authenticates the user. ''' try: - user = MdlUser.objects.get(username=username) + user = MoodleUser.objects.get(username=username) pwd = user.password uid = user.id firstname = user.firstname lastname = user.lastname email_id = user.email p = hashlib.md5(password) - pwd_valid = (pwd == p.hexdigest()) + pwd_valid = (pwd == p.hexdigest()) if user and pwd_valid: - try: - user = User.objects.get(username=username) - return user - except Exception, e: - user=User(id=uid, username=username, password=pwd,\ - first_name=firstname, last_name=lastname,\ - email=email_id) - user.save() - return user + try: + user = User.objects.get(username=username) + return user + except Exception, e: + user = User(id=uid, username=username, password=pwd, + first_name=firstname, last_name=lastname, + email=email_id) + user.save() + return user except Exception, e: return None diff --git a/testapp/myauthentication/models_spoken.py b/testapp/myauthentication/models_spoken_tutorial.py index 2526a0e..d333400 100644 --- a/testapp/myauthentication/models_spoken.py +++ b/testapp/myauthentication/models_spoken_tutorial.py @@ -9,7 +9,7 @@ from django.db import models -class MdlUser(models.Model): +class MoodleUser(models.Model): id = models.BigIntegerField(primary_key=True) username = models.CharField(unique=True, max_length=300) password = models.CharField(max_length=96) diff --git a/testapp/myauthentication/router.py b/testapp/myauthentication/router.py index eeb4cdb..3d9c330 100644 --- a/testapp/myauthentication/router.py +++ b/testapp/myauthentication/router.py @@ -8,5 +8,5 @@ class MyDatabaseRouter(object): database. """ if model._meta.app_label == 'myauthentication': - return 'spoken' + return 'spoken_tutorial' return None diff --git a/testapp/myauthentication/tests.py b/testapp/myauthentication/tests.py index 501deb7..4103038 100644 --- a/testapp/myauthentication/tests.py +++ b/testapp/myauthentication/tests.py @@ -1,16 +1,5 @@ -""" -This file demonstrates writing tests using the unittest module. These will pass -when you run "manage.py test". +#This file demonstrates writing tests using the unittest module. These will pass +#when you run "manage.py test". -Replace this with more appropriate tests for your application. -""" +#Write appropriate tests for the application. -from django.test import TestCase - - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.assertEqual(1 + 1, 2) |