<commit_before>from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User

from accounts.forms import LoginForm, RegistrationForm
from lists.forms import TodoForm


def login_view(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('lists:index')
        # else: show error message
    else:
        return render(request, 'accounts/login.html', {'form': LoginForm()})

    return render(request, 'lists/index.html', {'form': TodoForm()})


def register(request):
    if request.method == 'POST':
        email = request.POST['email']
        username = request.POST['username']
        password = request.POST['password']
        password_confirmation = request.POST['password_confirmation']
        # TODO add proper password check
        assert password == password_confirmation
        User.objects.create_user(username, email=email, password=password)
        return redirect('auth:login')
    else:
        return render(request, 'accounts/register.html',
                      {'form': RegistrationForm()})


def logout_view(request):
    logout(request)
<commit_msg>Redirect to index after login.<commit_after>from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User

from accounts.forms import LoginForm, RegistrationForm
from lists.forms import TodoForm


def login_view(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('lists:index')
        # else: show error message
    else:
        return render(request, 'accounts/login.html', {'form': LoginForm()})

    return redirect('lists:index')


def register(request):
    if request.method == 'POST':
        email = request.POST['email']
        username = request.POST['username']
        password = request.POST['password']
        password_confirmation = request.POST['password_confirmation']
        # TODO add proper password check
        assert password == password_confirmation
        User.objects.create_user(username, email=email, password=password)
        return redirect('auth:login')
    else:
        return render(request, 'accounts/register.html',
                      {'form': RegistrationForm()})


def logout_view(request):
    logout(request)

{'fraction_non_alphanumeric': 0.10583304226336011, 'fraction_numerical': 0.0, 'mean_word_length': 3.0624113475177306, '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': '62908', 'n_tokens_mistral': 742, 'n_tokens_neox': 717, 'n_words': 195}