def resend_link(request): """resend confirmation link""" email = request.POST.get("email") user = get_object_or_404(models.User, email=email) emailing.email_confirmation_email(user) return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": True})
def post(self, request): """resend confirmation link""" email = request.POST.get("email") try: user = models.User.objects.get(email=email) except models.User.DoesNotExist: return self.get(request, error=True) emailing.email_confirmation_email(user) return TemplateResponse(request, "confirm_email/confirm_email.html", {"valid": True})
def post(self, request): """join the server""" settings = models.SiteSettings.get() # no registration allowed when the site is being installed if settings.install_mode: raise PermissionDenied() if not settings.allow_registration: invite_code = request.POST.get("invite_code") if not invite_code: raise PermissionDenied() invite = get_object_or_404(models.SiteInvite, code=invite_code) if not invite.valid(): raise PermissionDenied() else: invite = None form = forms.RegisterForm(request.POST) if not form.is_valid(): data = { "login_form": forms.LoginForm(), "register_form": form, "invite": invite, "valid": invite.valid() if invite else True, } if invite: return TemplateResponse(request, "landing/invite.html", data) return TemplateResponse(request, "landing/login.html", data) localname = form.data["localname"].strip() email = form.data["email"] password = form.data["password"] # make sure the email isn't blocked as spam email_domain = email.split("@")[-1] if models.EmailBlocklist.objects.filter(domain=email_domain).exists(): # treat this like a successful registration, but don't do anything return redirect("confirm-email") username = f"{localname}@{DOMAIN}" user = models.User.objects.create_user( username, email, password, localname=localname, local=True, deactivation_reason="pending" if settings.require_confirm_email else None, is_active=not settings.require_confirm_email, ) if invite: invite.times_used += 1 invite.invitees.add(user) invite.save() if settings.require_confirm_email: emailing.email_confirmation_email(user) return redirect("confirm-email") login(request, user) return redirect("get-started-profile")
def post(self, request): """join the server""" settings = models.SiteSettings.get() if not settings.allow_registration: invite_code = request.POST.get("invite_code") if not invite_code: raise PermissionDenied invite = get_object_or_404(models.SiteInvite, code=invite_code) if not invite.valid(): raise PermissionDenied else: invite = None form = forms.RegisterForm(request.POST) errors = False if not form.is_valid(): errors = True localname = form.data["localname"].strip() email = form.data["email"] password = form.data["password"] # check localname and email uniqueness if models.User.objects.filter(localname=localname).first(): form.errors["localname"] = [ "User with this username already exists" ] errors = True if errors: data = { "login_form": forms.LoginForm(), "register_form": form, "invite": invite, "valid": invite.valid() if invite else True, } if invite: return TemplateResponse(request, "invite.html", data) return TemplateResponse(request, "login.html", data) username = "******" % (localname, DOMAIN) user = models.User.objects.create_user( username, email, password, localname=localname, local=True, deactivation_reason="pending" if settings.require_confirm_email else None, is_active=not settings.require_confirm_email, ) if invite: invite.times_used += 1 invite.invitees.add(user) invite.save() if settings.require_confirm_email: emailing.email_confirmation_email(user) return redirect("confirm-email") login(request, user) return redirect("get-started-profile")