Commit c7d379be by Brian Wilson

add first pass at wiring test registration dialog

parent b2117c11
......@@ -26,7 +26,7 @@ from bs4 import BeautifulSoup
from django.core.cache import cache
from django_future.csrf import ensure_csrf_cookie, csrf_exempt
from student.models import (Registration, UserProfile,
from student.models import (Registration, UserProfile, TestCenterUser,
PendingNameChange, PendingEmailChange,
CourseEnrollment, unique_id_for_user)
......@@ -205,6 +205,14 @@ def dashboard(request):
user = request.user
enrollments = CourseEnrollment.objects.filter(user=user)
# we want to populate the registration page with the relevant information,
# if it already exists. Create an empty object otherwise.
try:
testcenteruser = TestCenterUser.objects.get(user=user)
except TestCenterUser.DoesNotExist:
testcenteruser = TestCenterUser()
testcenteruser.user = user
# Build our courses list for the user, but ignore any courses that no longer
# exist (because the course IDs have changed). Still, we don't delete those
# enrollments, because it could have been a data push snafu.
......@@ -244,6 +252,7 @@ def dashboard(request):
'show_courseware_links_for' : show_courseware_links_for,
'cert_statuses': cert_statuses,
'news': top_news,
'testcenteruser': testcenteruser,
}
return render_to_response('dashboard.html', context)
......@@ -586,6 +595,83 @@ def create_account(request, post_override=None):
js = {'success': True}
return HttpResponse(json.dumps(js), mimetype="application/json")
@ensure_csrf_cookie
def create_test_registration(request, post_override=None):
'''
JSON call to create test registration.
Used by form in test_center_register_modal.html, which is included
into dashboard.html
'''
js = {'success': False}
post_vars = post_override if post_override else request.POST
# Confirm we have a properly formed request
for a in ['first_name', 'last_name', 'address_1', 'city', 'country']:
if a not in post_vars:
js['value'] = "Error (401 {field}). E-mail us.".format(field=a)
js['field'] = a
return HttpResponse(json.dumps(js))
# Confirm appropriate fields are there.
for a in ['first_name', 'last_name', 'address_1', 'city', 'country']:
if len(post_vars[a]) < 2:
error_str = {'first_name': 'First name must be minimum of two characters long.',
'last_name': 'Last name must be minimum of two characters long.',
'address_1': 'Last name must be minimum of two characters long.',
'city': 'Last name must be minimum of two characters long.',
'country': 'Last name must be minimum of two characters long.',
}
js['value'] = error_str[a]
js['field'] = a
return HttpResponse(json.dumps(js))
# Once the test_center_user information has been validated, create the entries:
ret = _do_create_or_update_test_center_user(post_vars)
if isinstance(ret,HttpResponse): # if there was an error then return that
return ret
(user, profile, testcenter_user, testcenter_registration) = ret
# only do the following if there is accommodation text to send,
# and a destination to which to send it:
if 'accommodation' in post_vars and settings.MITX_FEATURES.get('ACCOMMODATION_EMAIL'):
d = {'accommodation': post_vars['accommodation']
}
# composes accommodation email
subject = render_to_string('emails/accommodation_email_subject.txt', d)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('emails/accommodation_email.txt', d)
# skip if destination email address is not specified
try:
dest_addr = settings.MITX_FEATURES['ACCOMMODATION_EMAIL']
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [dest_addr], fail_silently=False)
except:
log.exception(sys.exc_info())
js['value'] = 'Could not send accommodation e-mail.'
return HttpResponse(json.dumps(js))
if DoExternalAuth:
eamap.user = login_user
eamap.dtsignup = datetime.datetime.now()
eamap.save()
log.debug('Updated ExternalAuthMap for %s to be %s' % (post_vars['username'],eamap))
if settings.MITX_FEATURES.get('BYPASS_ACTIVATION_EMAIL_FOR_EXTAUTH'):
log.debug('bypassing activation email')
login_user.is_active = True
login_user.save()
# statsd.increment("common.student.account_created")
js = {'success': True}
return HttpResponse(json.dumps(js), mimetype="application/json")
def get_random_post_override():
"""
......@@ -641,7 +727,7 @@ def password_reset(request):
# By default, Django doesn't allow Users with is_active = False to reset their passwords,
# but this bites people who signed up a long time ago, never activated, and forgot their
# password. So for their sake, we'll auto-activate a user for whome password_reset is called.
# password. So for their sake, we'll auto-activate a user for whom password_reset is called.
try:
user = User.objects.get(email=request.POST['email'])
user.is_active = True
......
......@@ -7,6 +7,7 @@
<%inherit file="main.html" />
<%namespace name='static' file='static_content.html'/>
<%include file="test_center_register_modal.html" />
<%block name="title"><title>Dashboard</title></%block>
......@@ -221,7 +222,7 @@
<!-- TODO: need to add logic to select which of the following to display. Like certs? -->
<div class="message message-status is-shown exam-register">
<a href="#exam_register" rel="leanModal" class="exam-button" id="exam_register_button">Register for Pearson exam</a>
<a href="#testcenter-register-modal" rel="leanModal" class="exam-button" id="exam_register_button">Register for Pearson exam</a>
<p class="message-copy">Registration for the Pearson exam is now open.</p>
</div>
......
......@@ -17,6 +17,10 @@
<div class="notice"></div>
<div id="register_error" class="modal-form-error" name="register_error"></div>
<div id="register_error" name="register_error"></div>
<!-- include these as pass-throughs -->
<input id="id_email" type="hidden" name="email" maxlength="75" value="${user.email}" />
<input id="id_username" type="hidden" name="username" maxlength="75" value="${user.username}" />
<!-- TODO: add the course somehow... -->
<!-- we should first start with information that we already know about the user,
though we should also give them the option to fix it.
......@@ -24,50 +28,50 @@
or candidate_id.
-->
<div class="input-group">
<label data-field="firstname">First Name*</label>
<input name="firstname" type="text" value="${firstname}" placeholder="e.g. Jane">
<label data-field="lastname">Last Name*</label>
<input name="lastname" type="text" value="${lastname}" placeholder="e.g. Smith">
<label data-field="middlename">Middle Name</label>
<input name="middlename" type="text" value="${middlename}" placeholder="e.g. Michael">
<label data-field="first_name">First Name*</label>
<input name="first_name" type="text" value="${testcenteruser.first_name}" maxlength="30" placeholder="e.g. Jane">
<label data-field="last_name">Last Name*</label>
<input name="last_name" type="text" value="${testcenteruser.last_name}" placeholder="e.g. Smith">
<label data-field="middle_name">Middle Name</label>
<input name="middle_name" type="text" value="${testcenteruser.middle_name}" placeholder="e.g. Michael">
<label data-field="suffix">Suffix</label>
<input name="suffix" type="text" value="${suffix}" placeholder="e.g. Jr.">
<input name="suffix" type="text" value="${testcenteruser.suffix}" placeholder="e.g. Jr.">
<label data-field="salutation">Salutation</label>
<input name="salutation" type="text" value="${salutation}" placeholder="e.g. Dr.">
<input name="salutation" type="text" value="${testcenteruser.salutation}" placeholder="e.g. Dr.">
</div>
<div class="input-group">
<label data-field="address1">Address1*</label>
<input name="address1" type="text" value="${address1}" placeholder="123 Main St.">
<label data-field="address2">Address2</label>
<input name="address2" type="text" value="${address2}" placeholder="Apartment 2B.">
<label data-field="address3">Address3</label>
<input name="address3" type="text" value="${address3}" placeholder="Attention: John Smith">
<label data-field="address_1">Address1*</label>
<input name="address_1" type="text" value="${testcenteruser.address_1}" placeholder="123 Main St.">
<label data-field="address_2">Address2</label>
<input name="address_2" type="text" value="${testcenteruser.address_2}" placeholder="Apartment 2B.">
<label data-field="address_3">Address3</label>
<input name="address_3" type="text" value="${testcenteruser.address_3}" placeholder="Attention: John Smith">
<label data-field="city">City</label>
<input name="city" type="text" value="${city}" placeholder="Our Fair City">
<input name="city" type="text" value="${testcenteruser.city}" placeholder="Our Fair City">
<label data-field="state">State/Province</label>
<input name="state" type="text" value="${state}" placeholder="MA">
<input name="state" type="text" value="${testcenteruser.state}" placeholder="MA">
<label data-field="postal_code">Postal Code</label>
<input name="postal_code" type="text" value="${postal_code}" placeholder="02138">
<input name="postal_code" type="text" value="${testcenteruser.postal_code}" placeholder="02138">
<label data-field="country">Country Code*</label>
<input name="country" type="text" value="${country}" placeholder="USA">
<input name="country" type="text" value="${testcenteruser.country}" placeholder="USA">
</div>
<!-- for now, just leave off the phone and company information -->
<div class="input-group">
<label data-field="phone">Phone*</label>
<input name="phone" type="text" value="${phone}" placeholder="1-23-456-7890">
<input name="phone" type="text" value="${testcenteruser.phone}" placeholder="1-23-456-7890">
<label data-field="phone">Extension</label>
<input name="extension" type="text" value="${extension}" placeholder="x123">
<label data-field="phone-country">Phone Country Code*</label>
<input name="phone-country" type="text" value="${phone_country}" placeholder="ABC">
<input name="extension" type="text" value="${testcenteruser.extension}" placeholder="x123">
<label data-field="phone_country_code">Phone Country Code*</label>
<input name="phone_country_code" type="text" value="${testcenteruser.phone_country_code}" placeholder="ABC">
<label data-field="fax">Fax</label>
<input name="fax" type="text" value="${fax}" placeholder="1-23-456-7891">
<label data-field="fax-country">Fax Country Code*</label>
<input name="fax-country" type="text" value="${fax_country}" placeholder="ABC">
<label data-field="company">Company</label>
<input name="company" type="text" value="${company}" placeholder="Acme Corporation">
<input name="fax" type="text" value="${testcenteruser.fax}" placeholder="1-23-456-7891">
<label data-field="fax_country_code">Fax Country Code*</label>
<input name="fax_country_code" type="text" value="${testcenteruser.fax_country_code}" placeholder="ABC">
<label data-field="company_name">Company</label>
<input name="company_name" type="text" value="${testcenteruser.company_name}" placeholder="Acme Corporation">
</div>
<div class="input-group">
......
......@@ -43,6 +43,8 @@ urlpatterns = ('',
url(r'^create_account$', 'student.views.create_account'),
url(r'^activate/(?P<key>[^/]*)$', 'student.views.activate_account', name="activate"),
url(r'^create_test_registration$', 'student.views.create_test_registration'),
url(r'^password_reset/$', 'student.views.password_reset', name='password_reset'),
## Obsolete Django views for password resets
## TODO: Replace with Mako-ized views
......
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