diff --git a/courseware/content_parser.py b/courseware/content_parser.py index 6203953fa4f171bb1c1968cb5d95c0c85b647f25..75b14acbbecd9459298959ffca1d33f200aa08e1 100644 --- a/courseware/content_parser.py +++ b/courseware/content_parser.py @@ -7,7 +7,7 @@ from mako.lookup import TemplateLookup try: # This lets us do __name__ == ='__main__' from django.conf import settings - from models import UserProfile + from user.models import UserProfile except: settings = None diff --git a/courseware/models.py b/courseware/models.py index fd88bea16c988f6affd66c14efa09399a168c780..5110f1d24fb65e3f9a821feaf0137f28934d0112 100644 --- a/courseware/models.py +++ b/courseware/models.py @@ -9,8 +9,6 @@ file and check it in at the same time as your model changes. To do that, 3. Add the migration file created in mitx/courseware/migrations/ """ -import uuid - from django.db import models from django.contrib.auth.models import User @@ -47,40 +45,3 @@ class StudentModule(models.Model): return self.module_type+'/'+self.student.username+"/"+self.module_id+'/'+str(self.state)[:20] -class UserProfile(models.Model): - class Meta: - db_table = "auth_userprofile" - - ## CRITICAL TODO/SECURITY - # Sanitize all fields. - # This is not visible to other users, but could introduce holes later - user = models.ForeignKey(User, unique=True, db_index=True) - name = models.TextField(blank=True, db_index=True) - language = models.TextField(blank=True, db_index=True) - location = models.TextField(blank=True, db_index=True) - meta = models.TextField(blank=True) # JSON dictionary for future expansion - courseware = models.TextField(blank=True, default='course.xml') - - -class Registration(models.Model): - ''' Allows us to wait for e-mail before user is registered. A - registration profile is created when the user creates an - account, but that account is inactive. Once the user clicks - on the activation key, it becomes active. ''' - class Meta: - db_table = "auth_registration" - - user = models.ForeignKey(User, unique=True) - activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True) - - def register(self, user): - # MINOR TODO: Switch to crypto-secure key - self.activation_key=uuid.uuid4().hex - self.user=user - self.save() - - def activate(self): - self.user.is_active = True - self.user.save() - self.delete() - diff --git a/courseware/module_render.py b/courseware/module_render.py index 85ece0f9cc46e8349ce0e7629d56d0c8698e962f..b4a0f994ba00759e5b54923a8fe0a13a63bce41e 100644 --- a/courseware/module_render.py +++ b/courseware/module_render.py @@ -19,7 +19,8 @@ from django.template import Context from django.template import Context, loader from mitxmako.shortcuts import render_to_response, render_to_string -from models import StudentModule, UserProfile +from models import StudentModule +from user.models import UserProfile import track.views import courseware.content_parser as content_parser diff --git a/courseware/views.py b/courseware/views.py index ffcac16951595b1d273312db4faf52a8a75cbb07..a292c577b1c9fcb68ce70db0df6e32d747bda9f0 100644 --- a/courseware/views.py +++ b/courseware/views.py @@ -17,8 +17,10 @@ from django.db import connection from lxml import etree -from models import StudentModule, UserProfile from module_render import render_module, modx_dispatch +from models import StudentModule +from user.models import UserProfile + import courseware.content_parser as content_parser import courseware.modules.capa_module diff --git a/settings_new_askbot.py b/settings_new_askbot.py index 95b4a79d34859bee8fc77fe5ef9fdfe1c798fe0e..30513c260af4a72978efd47ec31ed6223a1643fc 100644 --- a/settings_new_askbot.py +++ b/settings_new_askbot.py @@ -112,7 +112,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'courseware', - 'auth', + 'user', 'django.contrib.humanize', 'static_template_view', 'staticbook', diff --git a/urls.py b/urls.py index 567d21950621677a43772da3e760b389193b207a..b10fde59c0665ba661bbd61305493dbbd5a89dc5 100644 --- a/urls.py +++ b/urls.py @@ -10,13 +10,13 @@ import django.contrib.auth.views urlpatterns = ('', url(r'^event$', 'track.views.user_track'), url(r'^t/(?P<template>[^/]*)$', 'static_template_view.views.index'), - url(r'^logout$', 'auth.views.logout_user'), + url(r'^logout$', 'user.views.logout_user'), url(r'^info$', 'util.views.info'), - url(r'^login$', 'auth.views.login_user'), - url(r'^login/(?P<error>[^/]*)$', 'auth.views.login_user'), - url(r'^create_account$', 'auth.views.create_account'), - url(r'^activate/(?P<key>[^/]*)$', 'auth.views.activate_account'), - url(r'^$', 'auth.views.index'), + url(r'^login$', 'user.views.login_user'), + url(r'^login/(?P<error>[^/]*)$', 'user.views.login_user'), + url(r'^create_account$', 'user.views.create_account'), + url(r'^activate/(?P<key>[^/]*)$', 'user.views.activate_account'), + url(r'^$', 'user.views.index'), url(r'^password_reset/$', 'django.contrib.auth.views.password_reset', dict(from_email='registration@mitx.mit.edu'),name='auth_password_reset'), # url(r'^password_reset/$', 'auth.views.password_reset'), @@ -42,12 +42,12 @@ url(r'^wiki/', include('simplewiki.urls')), url(r'^courseware/(?P<course>[^/]*)/$', 'courseware.views.index'), url(r'^modx/(?P<module>[^/]*)/(?P<id>[^/]*)/(?P<dispatch>[^/]*)$', 'courseware.views.modx_dispatch'), #reset_problem'), url(r'^profile$', 'courseware.views.profile'), - url(r'^change_setting$', 'auth.views.change_setting'), + url(r'^change_setting$', 'user.views.change_setting'), url(r'^s/(?P<template>[^/]*)$', 'static_template_view.views.auth_index'), url(r'^book/(?P<page>[^/]*)$', 'staticbook.views.index'), url(r'^book-shifted/(?P<page>[^/]*)$', 'staticbook.views.index_shifted'), url(r'^book*$', 'staticbook.views.index'), -# url(r'^course_info/$', 'auth.views.courseinfo'), +# url(r'^course_info/$', 'user.views.courseinfo'), # url(r'^show_circuit/(?P<circuit>[^/]*)$', 'circuit.views.show_circuit'), url(r'^edit_circuit/(?P<circuit>[^/]*)$', 'circuit.views.edit_circuit'), url(r'^save_circuit/(?P<circuit>[^/]*)$', 'circuit.views.save_circuit'), diff --git a/auth/__init__.py b/user/__init__.py similarity index 100% rename from auth/__init__.py rename to user/__init__.py diff --git a/user/models.py b/user/models.py new file mode 100644 index 0000000000000000000000000000000000000000..1f9300e6b841d395c44fb55c9378e7e158ff7532 --- /dev/null +++ b/user/models.py @@ -0,0 +1,52 @@ +""" +WE'RE USING MIGRATIONS! + +If you make changes to this model, be sure to create an appropriate migration +file and check it in at the same time as your model changes. To do that, + +1. Go to the mitx dir +2. ./manage.py schemamigration users --auto description_of_your_change +3. Add the migration file created in mitx/courseware/migrations/ +""" +import uuid + +from django.db import models +from django.contrib.auth.models import User + +class UserProfile(models.Model): + class Meta: + db_table = "auth_userprofile" + + ## CRITICAL TODO/SECURITY + # Sanitize all fields. + # This is not visible to other users, but could introduce holes later + user = models.ForeignKey(User, unique=True, db_index=True) + name = models.TextField(blank=True, db_index=True) + language = models.TextField(blank=True, db_index=True) + location = models.TextField(blank=True, db_index=True) + meta = models.TextField(blank=True) # JSON dictionary for future expansion + courseware = models.TextField(blank=True, default='course.xml') + + +class Registration(models.Model): + ''' Allows us to wait for e-mail before user is registered. A + registration profile is created when the user creates an + account, but that account is inactive. Once the user clicks + on the activation key, it becomes active. ''' + class Meta: + db_table = "auth_registration" + + user = models.ForeignKey(User, unique=True) + activation_key = models.CharField(('activation key'), max_length=32, unique=True, db_index=True) + + def register(self, user): + # MINOR TODO: Switch to crypto-secure key + self.activation_key=uuid.uuid4().hex + self.user=user + self.save() + + def activate(self): + self.user.is_active = True + self.user.save() + self.delete() + diff --git a/auth/tests.py b/user/tests.py similarity index 100% rename from auth/tests.py rename to user/tests.py diff --git a/auth/views.py b/user/views.py similarity index 99% rename from auth/views.py rename to user/views.py index 655a0a863413c10679716381a3b235211ac859db..5b4db1081955351da8318dab443f8431f418070b 100644 --- a/auth/views.py +++ b/user/views.py @@ -13,9 +13,10 @@ from django.db import connection from django.http import HttpResponse, Http404 from django.shortcuts import redirect from mitxmako.shortcuts import render_to_response, render_to_string -from courseware.models import Registration, UserProfile -log = logging.getLogger("mitx.auth") +from models import Registration, UserProfile + +log = logging.getLogger("mitx.user") def csrf_token(context): csrf_token = context.get('csrf_token', '')