<commit_before>from django.template import RequestContext
from django.forms import ModelForm
from django.http import HttpResponseRedirect
from django.shortcuts import render, render_to_response,redirect
from django.core.context_processors import csrf
from django.utils.translation import ugettext as _
from django.contrib import messages
from structure.forms import LIITRegistrationForm
from django.contrib.auth import authenticate, login, logout

def index(request):
    if not request.user.is_authenticated():
        return redirect('/login')
    return render(request, 'users/index.html')

def register(request):
    if request.user.is_authenticated():
        return redirect('/home')
    if request.method == 'POST':
        form = LIITRegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            messages.add_message(request, messages.SUCCESS, _('You have successfully registered! You can now log in.'))
            return redirect('/login')
    else:
        form = LIITRegistrationForm()
    return render(request, 'users/register.html', { 'form': form, })

def custom_login(request):
    state = None
    username = password = ''
    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                state = _("You're successfully logged in!")
                return redirect('/home')
            else:
                state = _("Your account is inactive, please contact the site admin.")
        else:
            state = ("Your username and/or password were incorrect.")

    return render_to_response('users/login.html', {'state': state, 'username': username},
                              context_instance=RequestContext(request))

def custom_logout(request):
    if request.user.is_authenticated():
        logout(request)
    return redirect('/login')
<commit_msg>On /login, redirect if user is already logged in<commit_after>from django.template import RequestContext
from django.forms import ModelForm
from django.http import HttpResponseRedirect
from django.shortcuts import render, render_to_response,redirect
from django.core.context_processors import csrf
from django.utils.translation import ugettext as _
from django.contrib import messages
from structure.forms import LIITRegistrationForm
from django.contrib.auth import authenticate, login, logout

def index(request):
    if not request.user.is_authenticated():
        return redirect('/login')
    return render(request, 'users/index.html')

def register(request):
    if request.user.is_authenticated():
        return redirect('/home')
    if request.method == 'POST':
        form = LIITRegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            messages.add_message(request, messages.SUCCESS, _('You have successfully registered! You can now log in.'))
            return redirect('/login')
    else:
        form = LIITRegistrationForm()
    return render(request, 'users/register.html', { 'form': form, })

def custom_login(request):
    if request.user.is_authenticated():
        return redirect('/home')
    state = None
    username = password = ''
    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                login(request, user)
                state = _("You're successfully logged in!")
                return redirect('/home')
            else:
                state = _("Your account is inactive, please contact the site admin.")
        else:
            state = ("Your username and/or password were incorrect.")

    return render_to_response('users/login.html', {'state': state, 'username': username},
                              context_instance=RequestContext(request))

def custom_logout(request):
    if request.user.is_authenticated():
        logout(request)
    return redirect('/login')

{'fraction_non_alphanumeric': 0.09971509971509972, 'fraction_numerical': 0.0, 'mean_word_length': 2.948453608247423, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5289866', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1049, 'n_words': 312}