<commit_before>from django.http import HttpResponse
from django.shortcuts import redirect, render_to_response
from pytask.taskapp.models import Task
from pytask.taskapp.forms.user import RegistrationForm, LoginForm
from pytask.taskapp.events.user import createUser
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.models import User

def redirect_to_homepage(request):
    """ simply redirect to homepage """
    
    return redirect('/')

def homepage(request):
    """ check for authentication and display accordingly. """
    
    user = request.user
    is_guest = False
    is_mentor = False
    can_create_task = False
    task_list = []
    
    if not user.is_authenticated():
        is_guest = True
        disp_num = 10
        tasks_count = Task.objects.count()
        if tasks_count <= disp_num:
            task_list = Task.objects.order_by('id').reverse()
        else:
            task_list = Task.objects.order_by('id').reverse()[:10]
    else:
        user_profile = user.get_profile()
        is_mentor = True if user.task_mentors.all() else False
        can_create_task = False if user_profile.rights == u"CT" else True
        
    context = {'user':user,
               'is_guest':is_guest,
               'is_mentor':is_mentor,
               'task_list':task_list,
               'can_create_task':can_create_task,
               }
               
    return render_to_response('index.html', context)


def register(request):
    """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            if data['password'] == data['<PASSWORD>']:
                try:
                    if User.objects.get(username__exact = data['username']):
                        errors=['Choose some other username']
                        return render_to_response('user/register.html',{'form':form,'errors':errors})
                except:
                     u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
                return redirect('/accounts/login/')
            else:
                errors=['Password do not match']
                form = RegistrationForm(request.POST)
                return render_to_response('user/register.html',{'form':form,'errors':errors})#HttpResponse('Password did not match')
        else:
            form = RegistrationForm()
    else:
        form = RegistrationForm()
    return render_to_response('user/register.html', {'form': form})

def user_login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                return redirect('/')# Redirect to a success page.<commit_msg>imposed a filter on username that it contains only alphabets and numbers.<commit_after>from django.http import HttpResponse
from django.shortcuts import redirect, render_to_response
from pytask.taskapp.models import Task
from pytask.taskapp.forms.user import RegistrationForm, LoginForm
from pytask.taskapp.events.user import createUser
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.models import User

def redirect_to_homepage(request):
    """ simply redirect to homepage """
    
    return redirect('/')

def homepage(request):
    """ check for authentication and display accordingly. """
    
    user = request.user
    is_guest = False
    is_mentor = False
    can_create_task = False
    task_list = []
    
    if not user.is_authenticated():
        is_guest = True
        disp_num = 10
        tasks_count = Task.objects.count()
        if tasks_count <= disp_num:
            task_list = Task.objects.order_by('id').reverse()
        else:
            task_list = Task.objects.order_by('id').reverse()[:10]
    else:
        user_profile = user.get_profile()
        is_mentor = True if user.task_mentors.all() else False
        can_create_task = False if user_profile.rights == u"CT" else True
        
    context = {'user':user,
               'is_guest':is_guest,
               'is_mentor':is_mentor,
               'task_list':task_list,
               'can_create_task':can_create_task,
               }
               
    return render_to_response('index.html', context)


def register(request):
    """ user registration: gets the user details and create the user and userprofile if data entered is valid"""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            if data['password'] == data['repeat_password']:
                if data['username'].isalnum():
                    try:
                        if User.objects.get(username__exact = data['username']):
                            errors=['Choose some other username']
                            return render_to_response('user/register.html',{'form':form,'errors':errors})
                    except:
                         u = createUser(username=data['username'], email=data['email'], password=data['password'],dob = data['dob'],gender = data['gender'])
                    return redirect('/accounts/login/')
                else:
                    errors = ['Username can contain only alphabets and numbers!']
                    return render_to_response('user/register.html',{'form':form,'errors':errors})
            else:
                errors=['Password do not match']
                form = RegistrationForm(request.POST)
                return render_to_response('user/register.html',{'form':form,'errors':errors})#HttpResponse('Password did not match')
        else:
            form = RegistrationForm()
    else:
        form = RegistrationForm()
    return render_to_response('user/register.html', {'form': form})

def user_login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                return redirect('/')# Redirect to a success page.
{'fraction_non_alphanumeric': 0.10835629017447199, 'fraction_numerical': 0.001224364860728497, 'mean_word_length': 2.361625514403292, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4786862', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1689, 'n_words': 421}