<commit_before>from django.urls import reverse, reverse_lazy
from django.views import generic
from django.http import HttpResponseRedirect
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login                    
import json


class IndexView(generic.RedirectView):
    url = '/photos/'

    def get(self, request, *args, **kwargs):
        return super().get(request, *args, **kwargs)


@csrf_exempt  
def api_login(request):
	if request.method == 'POST':
		body_unicode = request.body.decode('utf-8')
		body = json.loads(body_unicode)

		user = authenticate(username=body['username'], password=body['password'])
		if user:
			return JsonResponse({'message': "Thank you for logging in.", 'token': user.auth_token.key})
		else:
			return JsonResponse({'message': 'Bad username or password.'})
	else:
		return HttpResponseRedirect(reverse('photos:list'))<commit_msg>Changed login from JSON in request.body to request.POST.<commit_after>from django.urls import reverse, reverse_lazy
from django.views import generic
from django.http import HttpResponseRedirect
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login                    
import json


class IndexView(generic.RedirectView):
    url = '/photos/'

    def get(self, request, *args, **kwargs):
        return super().get(request, *args, **kwargs)


@csrf_exempt  
def api_login(request):
	if request.method == 'POST':
		user = authenticate(username=request.POST['username'], password=request.POST['password'])
		if user:
			return JsonResponse({
				'message': "Thank you for logging in.",
				'id': user.id,
				'username': user.username,
				'token': user.auth_token.key
			})
		else:
			return JsonResponse({
				'message': 'Bad username or password.',
				'id': None,
				'username': None,
				'token': None
			})
	else:
		return HttpResponseRedirect(reverse('photos:list'))
{'fraction_non_alphanumeric': 0.1185149928605426, 'fraction_numerical': 0.00047596382674916705, 'mean_word_length': 4.308080808080808, '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': '4512916', 'n_tokens_mistral': 657, 'n_tokens_neox': 596, 'n_words': 172}