from django.shortcuts import render
from django.http import JsonResponse
import common.render
from common.settings import get_page_config


def form(request):
    ''' The signup form webpage '''
    context = get_page_config(title='New User Sign Up')
    context['form'] = [
        {'label': 'User Name', 'name': 'username'},
        {'label': 'Email Address', 'name': 'email'},
        {'label': 'Password', 'type': 'password', 'name':'password'},
        {'label': 'Re-enter Password', 'type': 'password', 'id':'repass'}
    ]
    context['validators'] = [ 'signup/newaccount_validator.js' ]
    return common.render.singleform(request, context)


def validate(request):
    ''' Signup form validation handler '''
    return JsonResponse({"status": "error", "message": "Test Case"})


def submit(request):
    ''' Signup form submission handler '''
    return HttpResponse('')

@@ -9,68 +9,227 @@
 ngo.
-shortcuts import render%0Afrom django.http import JsonResponse
+http import JsonResponse%0Afrom django.contrib.auth.models import User%0Afrom django.core.validators import validate_email%0Afrom django.core.exceptions import ValidationError%0Afrom django.shortcuts import render%0Aimport urllib
 %0Aimp
@@ -861,32 +861,425 @@
 ion handler '''%0A
+    msg = ''%0A    if not('username' in request.GET):%0A        msg = 'Name not given!'%0A    elif not('email' in request.GET):%0A        msg = 'Email not given!'%0A    name = urllib.unquote(request.GET%5B'username'%5D)%0A    email = urllib.unquote(request.GET%5B'email'%5D)%0A    if not msg: msg = __validate_name__(name)%0A    if not msg: msg = __validate_email__(email)%0A%0A    status = 'error' if msg else 'success'%0A
     return JsonR
@@ -1301,15 +1301,14 @@
 s%22: 
-%22error%22
+status
 , %22m
@@ -1320,19 +1320,11 @@
 e%22: 
-%22Test Case%22
+msg
 %7D)%0A%0A
@@ -1416,8 +1416,594 @@
 nse('')%0A
+%0A%0Adef __validate_name__(name):%0A    ''' Internal validation function for username '''%0A    lname = len(name)%0A    if lname %3C 5:%0A        return 'User name must be at least 5 characters long'%0A    if lname %3E 64:%0A        return 'User name must not be longer than 64 characters'%0A    if len(User.objects.filter(username=name)):%0A        return 'User name already in use'%0A    return ''%0A%0Adef __validate_email__(email):%0A    ''' Internal validation function for email '''%0A    try:%0A        validate_email(email)%0A    except ValidationError:%0A        return 'Invalid email address: '+email%0A    return ''%0A

Implement backend newaccount form verification