<filename>students/K33422/laboratory_works/Daria Plotskaya/lab_2/users/views.py
from django.views.generic.edit import FormView
from django.contrib.auth import login, authenticate
from django.urls import reverse_lazy
from .forms import CustomUserCreationForm


# Представление с формой для регистрации пользователя
class UserCreateFormView(FormView):
    form_class = CustomUserCreationForm
    template_name = "registration/register.html"
    success_url = reverse_lazy("index")

    def form_valid(self, form):
        form.save()
        username = form.cleaned_data.get('username')
        raw_password = form.cleaned_data.get('<PASSWORD>')
        user = authenticate(username=username, password=<PASSWORD>)
        login(self.request, user)
        return super(UserCreateFormView, self).form_valid(form)
