From 77caf5d44ab14d56efd4acbc65a6dd2d78c1c1a6 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Fri, 6 Jun 2014 15:20:45 +0530 Subject: changes made as per comments. --- testapp/myauthentication/README | 2 +- testapp/myauthentication/backend.py | 25 +++++++++++---------- testapp/myauthentication/models_spoken.py | 26 ---------------------- testapp/myauthentication/models_spoken_tutorial.py | 26 ++++++++++++++++++++++ testapp/myauthentication/router.py | 2 +- testapp/myauthentication/tests.py | 17 +++----------- testapp/settings.py | 2 +- 7 files changed, 45 insertions(+), 55 deletions(-) delete mode 100644 testapp/myauthentication/models_spoken.py create mode 100644 testapp/myauthentication/models_spoken_tutorial.py (limited to 'testapp') 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.py deleted file mode 100644 index 2526a0e..0000000 --- a/testapp/myauthentication/models_spoken.py +++ /dev/null @@ -1,26 +0,0 @@ -# This is an auto-generated Django model module. -# You'll have to do the following manually to clean this up: -# * Rearrange models' order -# * Make sure each model has one field with primary_key=True -# Feel free to rename the models, but don't rename db_table values or field names. -# -# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]' -# into your database. - -from django.db import models - -class MdlUser(models.Model): - id = models.BigIntegerField(primary_key=True) - username = models.CharField(unique=True, max_length=300) - password = models.CharField(max_length=96) - idnumber = models.CharField(max_length=765) - firstname = models.CharField(max_length=300) - lastname = models.CharField(max_length=300) - email = models.CharField(max_length=300) - institution = models.CharField(max_length=120) - department = models.CharField(max_length=90) - address = models.CharField(max_length=210) - city = models.CharField(max_length=360) - country = models.CharField(max_length=6) - class Meta: - db_table = u'mdl_user' diff --git a/testapp/myauthentication/models_spoken_tutorial.py b/testapp/myauthentication/models_spoken_tutorial.py new file mode 100644 index 0000000..d333400 --- /dev/null +++ b/testapp/myauthentication/models_spoken_tutorial.py @@ -0,0 +1,26 @@ +# This is an auto-generated Django model module. +# You'll have to do the following manually to clean this up: +# * Rearrange models' order +# * Make sure each model has one field with primary_key=True +# Feel free to rename the models, but don't rename db_table values or field names. +# +# Also note: You'll have to insert the output of 'django-admin.py sqlcustom [appname]' +# into your database. + +from django.db import models + +class MoodleUser(models.Model): + id = models.BigIntegerField(primary_key=True) + username = models.CharField(unique=True, max_length=300) + password = models.CharField(max_length=96) + idnumber = models.CharField(max_length=765) + firstname = models.CharField(max_length=300) + lastname = models.CharField(max_length=300) + email = models.CharField(max_length=300) + institution = models.CharField(max_length=120) + department = models.CharField(max_length=90) + address = models.CharField(max_length=210) + city = models.CharField(max_length=360) + country = models.CharField(max_length=6) + class Meta: + db_table = u'mdl_user' 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) diff --git a/testapp/settings.py b/testapp/settings.py index cc84095..f1ef0ba 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -49,7 +49,7 @@ DATABASES = { 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. }, - 'spoken' : { + 'spoken_tutorial' : { 'ENGINE' : 'django.db.backends.mysql', 'NAME' : 'YOUR DATABASE', 'USER' : 'YOUR USERNAME', -- cgit