parameters: (request)
docstring: A registration form endpoint for registering and logging in.
  
      This view will permit a user to register if their username is unique,
      their password is not empty, and an email address is provided.
      This view returns JSON, with a 'success' property if registration or
      login was successful.
  
      If registration was successful, the JSON also contains
      a 'redirect' property.
  
      If registration was unsuccessful, the JSON also contains
      a 'message' property, describing why the registration failed.
  
      Parameters:
          request -- An HttpRequest, with the form submitted parameters.
  
      Returns:
          A JSON object indicating if registration/login was successful.
docstring_summary: A registration form endpoint for registering and logging in.
docstring_tokens: A registration form endpoint for registering and logging in .
function: def userregister(request):
      """
      A registration form endpoint for registering and logging in.
  
      This view will permit a user to register if their username is unique,
      their password is not empty, and an email address is provided.
      This view returns JSON, with a 'success' property if registration or
      login was successful.
  
      If registration was successful, the JSON also contains
      a 'redirect' property.
  
      If registration was unsuccessful, the JSON also contains
      a 'message' property, describing why the registration failed.
  
      Parameters:
          request -- An HttpRequest, with the form submitted parameters.
  
      Returns:
          A JSON object indicating if registration/login was successful.
      """
      username = request.POST.get('newusername', None)
      password = request.POST.get('newpassword1', None)
      email = request.POST.get('email', None)
      fname = request.POST.get('firstname', None)
      lname = request.POST.get('lastname', None)
      hint = request.POST.get('passwordhint', None)
      org = request.POST.get('organization', None)
      anonymous = False
      status = {'success': False}
      if username != '' and password != '':
          if (username == 'anonymous' and password == 'anonymous'):
              user = AnonymousUser()
          else:
              name_exists = User.objects.filter(username__exact=username)
              if name_exists:
                  status['message'] = 'name exists'
                  return HttpResponse(json.dumps(status))
  
              email_exists = email != '' and User.objects.filter(
                  email__exact=email)
              if email_exists:
                  status['message'] = 'email exists'
                  return HttpResponse(json.dumps(status))
  
              try:
                  User.objects.create_user(username, email, password)
              except Exception as error:
                  status[
                      'message'] = 'Sorry, we weren\'t able to create your account.'
                  return HttpResponse(json.dumps(status))
  
              # authenticate the user, and add additional registration info
              user = authenticate(username=username, password=password)
  
              user.first_name = fname
              user.last_name = lname
              user.save()
  
              profile = user.profile
              profile.organization = org
              profile.pass_hint = hint
              profile.save()
  
              login(request, user)
  
          status['success'] = True
          status['redirect'] = '/districtmapping/plan/0/view/'
          return HttpResponse(json.dumps(status))
      else:
          status['message'] = 'Username cannot be empty.'
          return HttpResponse(json.dumps(status))
function_tokens: def userregister ( request ) : username = request . POST . get ( 'newusername' , None ) password = request . POST . get ( 'newpassword1' , None ) email = request . POST . get ( 'email' , None ) fname = request . POST . get ( 'firstname' , None ) lname = request . POST . get ( 'lastname' , None ) hint = request . POST . get ( 'passwordhint' , None ) org = request . POST . get ( 'organization' , None ) anonymous = False status = { 'success' : False } if username != '' and password != '' : if ( username == 'anonymous' and password == 'anonymous' ) : user = AnonymousUser ( ) else : name_exists = User . objects . filter ( username__exact = username ) if name_exists : status [ 'message' ] = 'name exists' return HttpResponse ( json . dumps ( status ) ) email_exists = email != '' and User . objects . filter ( email__exact = email ) if email_exists : status [ 'message' ] = 'email exists' return HttpResponse ( json . dumps ( status ) ) try : User . objects . create_user ( username , email , password ) except Exception as error : status [ 'message' ] = 'Sorry, we weren\'t able to create your account.' return HttpResponse ( json . dumps ( status ) ) # authenticate the user, and add additional registration info user = authenticate ( username = username , password = password ) user . first_name = fname user . last_name = lname user . save ( ) profile = user . profile profile . organization = org profile . pass_hint = hint profile . save ( ) login ( request , user ) status [ 'success' ] = True status [ 'redirect' ] = '/districtmapping/plan/0/view/' return HttpResponse ( json . dumps ( status ) ) else : status [ 'message' ] = 'Username cannot be empty.' return HttpResponse ( json . dumps ( status ) )