<commit_before>from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import authenticate,login,logout
from django.contrib import messages
from django.shortcuts import render,redirect
from django.views import View
from django.views.generic.edit import FormView


from . import forms
from . import models

# Create your views here.
class LoginView(FormView):
    template_name = 'passwordless/login.html'
    form_class = forms.LoginForm
    success_url = '/'

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['request'] = self.request
        return kwargs

    def form_valid(self, form):
        form.send_email()

        return super().form_valid(form)


class RegisterView(LoginView):
    template_name = 'passwordless/register.html'
    form_class = forms.RegistrationForm

    def form_valid(self, form):
        form.create_user()

        return super().form_valid(form)


class AuthnView(View):
    def get(self, request, token):
        user = authenticate(token=token)
        if user is not None:
            login(request, user)
            return redirect('chat:index')
        else:
            if request.user.is_authenticated:
                messages.info(request, 'You are already authenticated on this site')
                return redirect('chat:index')
            else:
                return render(request, 'passwordless/invalid.html')


class LogoutView(View):
    def get(self, request):
        logout(request)
        messages.success(request, 'You are now logged out of the site')
        return redirect('index')
<commit_msg>Users now actually activated on first login<commit_after>from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth import authenticate,login,logout
from django.contrib import messages
from django.shortcuts import render,redirect
from django.views import View
from django.views.generic.edit import FormView


from . import forms
from . import models

# Create your views here.
class LoginView(FormView):
    template_name = 'passwordless/login.html'
    form_class = forms.LoginForm
    success_url = '/'

    def get_form_kwargs(self):
        kwargs = super().get_form_kwargs()
        kwargs['request'] = self.request
        return kwargs

    def form_valid(self, form):
        form.send_email()

        return super().form_valid(form)


class RegisterView(LoginView):
    template_name = 'passwordless/register.html'
    form_class = forms.RegistrationForm

    def form_valid(self, form):
        form.create_user()

        return super().form_valid(form)


class AuthnView(View):
    def get(self, request, token):
        user = authenticate(token=token)
        if user is not None:
            login(request, user)

            if not user.is_active:
                # Activate the user
                user.is_active = True
                user.save()

                messages.success(request, 'Your account is now active on this site')

            return redirect('chat:index')
        else:
            if request.user.is_authenticated:
                messages.info(request, 'You are already authenticated on this site')
                return redirect('chat:index')
            else:
                return render(request, 'passwordless/invalid.html')


class LogoutView(View):
    def get(self, request):
        logout(request)
        messages.success(request, 'You are now logged out of the site')
        return redirect('index')

{'fraction_non_alphanumeric': 0.08750357449242208, 'fraction_numerical': 0.0, 'mean_word_length': 2.713375796178344, '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': '7448098', 'n_tokens_mistral': 958, 'n_tokens_neox': 918, 'n_words': 260}