45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import logging
|
|
|
|
# import stripe
|
|
from django.conf import settings
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.shortcuts import redirect, render
|
|
from django.urls import reverse, reverse_lazy
|
|
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)
|