<commit_before>from django.contrib.auth import authenticate, logout
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse, reverse_lazy
from django.db import transaction
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.shortcuts import render
from django.views import generic
from django.views.decorators.csrf import csrf_exempt
import json

from .models import Todo

# Create your views here.
def login(request):
    from django.contrib.auth import login

    user = None

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username = username, password = password)

        if user is not None and user.is_active:
            login(request, user)
            return HttpResponseRedirect(reverse('todo:index'))

    return render(request, 'todo/login.html', {<commit_msg>modify login logic(if already logined, redirect to index page)<commit_after>from django.contrib.auth import authenticate, logout
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse, reverse_lazy
from django.db import transaction
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.shortcuts import render
from django.views import generic
from django.views.decorators.csrf import csrf_exempt
import json

from .models import Todo

# Create your views here.
def login(request):
    from django.contrib.auth import login

    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('todo:index'))

    user = None

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username = username, password = password)

        if user is not None and user.is_active:
            login(request, user)
            return HttpResponseRedirect(reverse('todo:index'))

    return render(request, 'todo/login.html', {
{'fraction_non_alphanumeric': 0.07947342759629449, 'fraction_numerical': 0.0, 'mean_word_length': 4.029411764705882, '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': '198406', 'n_tokens_mistral': 539, 'n_tokens_neox': 523, 'n_words': 172}