<commit_before>import random
import calendar
from datetime import timedelta
from PIL import Image
import datetime
from django.db.models import Count, Q
from django.db.models import Sum
from django.template.loader import get_template
from django.template import Context
from django.core import serializers
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.db.utils import IntegrityError
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.shortcuts import render, render_to_response
from main.models import Users, Persons, Session, Groups, GroupLists, Images, Views
from django.http import HttpResponse, JsonResponse
from django.forms import EmailField
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.csrf import csrf_exempt
import simplejson as json
import logging
from django.shortcuts import redirect
# import pdb
import sys
import os
from project_391.settings import PROJECT_PATH
from main.datacube import generateDataCube
# Create your views here.

PUBLIC = 1 # group id for public group
PRIVATE = 2 # group id for private group

def loginPage(request):         # how do we respond to a request for a login page?

    if len(request.POST) == 0:  # "Sign In" not clicked, display log in page
        return render(request, 'main/login.html')

    # Otherwise, validate the login
    POST_username = request.POST.get('USERNAME', None)
    POST_password = request.POST.get('PASSWORD', None)
    error_msg = None

    if POST_username and POST_password:
        try:
            user = Users.objects.get(username=POST_username)
        except ObjectDoesNotExist:
            error_msg = "User %s does not exist." % POST_username
        else:
            if user.password == POST_password:
                # Send them to the index page, and store a unique sessiontracker for this session.
                response = render_to_response('main/home_page.html',
                                              {'password':<PASSWORD>, 'username':POST_username},
                                              RequestContext(request))
                st = str(hash(POST_username+str(random.random()))) # generate sessiontracker
                response.set_cookie('sessiontracker', st)                
                
                # delete any old sessions. NOTE: this means only one user account may be logged in
                # at once. we can fix this later if need be.
                Session.objects.filter(username=user).delete()
                Session.objects.create(username=user, sessiontracker=st)
                
                return response
            else:
                error_msg = "Incorrect Password, please try again."
    else:
        error_msg = "Please supply a username and password."

    error_msg = error_msg if error_msg else "Unknown Error, please report"
    return render(request, 'main/login.html', {'error_msg' : error_msg})

################################################################################

def register(request):
    if len(request.POST) == 0:  # "Register" wasn't clicked; display the empty registration page
        return render(request, 'main/register.html')

    # Get form data
    firstname       = request.POST.get('FIRSTNAME', None)
    lastname        = request.POST.get('LASTNAME', None)
    username        = request.POST.get('USERNAME', None)
    address         = request.POST.get('ADDRESS', None)
    email           = request.POST.get('EMAIL', None)
    phone           = request.POST.get('PHONE', None)
    password        = request.POST.get('PASSWORD', None)
    passwordconfirm = request.POST.get('PASSWORDCONFIRM', None)

    ### Validation ###
    err_pass_not_match = False
    err_username_taken = False

    # Check whether username already exists
    try:
        Users.objects.get(username=username)
    except ObjectDoesNotExist: # good
        pass
    else:
        err_username_taken = True
<commit_msg>Fixed email validation UnboundLocalError<commit_after>import random
import calendar
from datetime import timedelta
from PIL import Image
import datetime
from django.db.models import Count, Q
from django.db.models import Sum
from django.template.loader import get_template
from django.template import Context
from django.core import serializers
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.db.utils import IntegrityError
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.shortcuts import render, render_to_response
from main.models import Users, Persons, Session, Groups, GroupLists, Images, Views
from django.http import HttpResponse, JsonResponse
from django.forms import EmailField
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.csrf import csrf_exempt
import simplejson as json
import logging
from django.shortcuts import redirect
# import pdb
import sys
import os
from project_391.settings import PROJECT_PATH
from main.datacube import generateDataCube
# Create your views here.

PUBLIC = 1 # group id for public group
PRIVATE = 2 # group id for private group

def loginPage(request):         # how do we respond to a request for a login page?

    if len(request.POST) == 0:  # "Sign In" not clicked, display log in page
        return render(request, 'main/login.html')

    # Otherwise, validate the login
    POST_username = request.POST.get('USERNAME', None)
    POST_password = request.POST.get('PASSWORD', None)
    error_msg = None

    if POST_username and POST_password:
        try:
            user = Users.objects.get(username=POST_username)
        except ObjectDoesNotExist:
            error_msg = "User %s does not exist." % POST_username
        else:
            if user.password == POST_password:
                # Send them to the index page, and store a unique sessiontracker for this session.
                response = render_to_response('main/home_page.html',
                                              {'password':<PASSWORD>, 'username':POST_username},
                                              RequestContext(request))
                st = str(hash(POST_username+str(random.random()))) # generate sessiontracker
                response.set_cookie('sessiontracker', st)                
                
                # delete any old sessions. NOTE: this means only one user account may be logged in
                # at once. we can fix this later if need be.
                Session.objects.filter(username=user).delete()
                Session.objects.create(username=user, sessiontracker=st)
                
                return response
            else:
                error_msg = "Incorrect Password, please try again."
    else:
        error_msg = "Please supply a username and password."

    error_msg = error_msg if error_msg else "Unknown Error, please report"
    return render(request, 'main/login.html', {'error_msg' : error_msg})

################################################################################

def register(request):
    if len(request.POST) == 0:  # "Register" wasn't clicked; display the empty registration page
        return render(request, 'main/register.html')

    # Get form data
    firstname       = request.POST.get('FIRSTNAME', None)
    lastname        = request.POST.get('LASTNAME', None)
    username        = request.POST.get('USERNAME', None)
    address         = request.POST.get('ADDRESS', None)
    email           = request.POST.get('EMAIL', None)
    phone           = request.POST.get('PHONE', None)
    password        = request.POST.get('PASSWORD', None)
    passwordconfirm = request.POST.get('PASSWORDCONFIRM', None)

    ### Validation ###
    err_pass_not_match = False
    err_username_taken = False
    err_email_taken = False

    # Check whether username already exists
    try:
        Users.objects.get(username=username)
    except ObjectDoesNotExist: # good
        pass
    else:
        err_username_taken = True

{'fraction_non_alphanumeric': 0.09575126966431315, 'fraction_numerical': 0.0017341756472191254, 'mean_word_length': 2.799529411764706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1328210', 'n_tokens_mistral': 2105, 'n_tokens_neox': 2017, 'n_words': 667}