Commit 72c45e8b by David Ormsbee

Move UserProfile and Registration out of courseware and into a renamed auth (now user)

--HG--
rename : auth/__init__.py => user/__init__.py
rename : auth/tests.py => user/tests.py
rename : auth/views.py => user/views.py
parent 40efe3e7
......@@ -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
......
......@@ -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()
......@@ -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
......
......@@ -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
......
......@@ -112,7 +112,7 @@ INSTALLED_APPS = (
'django.contrib.messages',
'django.contrib.staticfiles',
'courseware',
'auth',
'user',
'django.contrib.humanize',
'static_template_view',
'staticbook',
......
......@@ -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'),
......
"""
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()
......@@ -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', '')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment