pluto/core/views/base.py

45 lines
1.3 KiB
Python
Raw Normal View History

2023-03-05 20:09:31 +00:00
import logging
# import stripe
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
2023-03-08 12:48:05 +00:00
from django.shortcuts import render
from django.urls import reverse_lazy
2023-03-05 20:09:31 +00:00
from django.views import View
from django.views.generic.edit import CreateView
from core.forms import NewUserForm
from core.lib.notify import raw_sendmsg
logger = logging.getLogger(__name__)
# Create your views here
class Home(LoginRequiredMixin, View):
template_name = "index.html"
def get(self, request):
return render(request, self.template_name)
class Signup(CreateView):
form_class = NewUserForm
success_url = reverse_lazy("two_factor:login")
template_name = "registration/signup.html"
def form_valid(self, form):
"""If the form is valid, save the associated model."""
self.object = form.save()
raw_sendmsg(
f"New user signup: {self.object.username} - {self.object.email}",
title="New user",
topic=settings.NOTIFY_TOPIC,
)
return super().form_valid(form)
def get(self, request, *args, **kwargs):
if not settings.REGISTRATION_OPEN:
return render(request, "registration/registration_closed.html")
return super().get(request, *args, **kwargs)