1

signup: fix bugs

This commit is contained in:
Motiejus Jakštys 2024-03-05 12:06:51 +02:00
parent 47d103e08c
commit 93653ee1bd
3 changed files with 9 additions and 5 deletions

View File

@ -5,7 +5,7 @@ class Signup(models.Model):
email = models.EmailField()
created_at = models.DateTimeField(auto_now_add=True)
anonymized_ip = models.GenericIPAddressField()
user_agent = models.CharField(max_length=255)
user_agent = models.CharField(max_length=255, blank=True)
geoip = models.JSONField(null=True, blank=True)
referrer = models.CharField(max_length=255, blank=True)

View File

@ -13,7 +13,7 @@ class SignupViewTest(TestCase):
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Hosted Syncthing")
def test_ok_signup(self):
def test_signup_ok(self):
resp = self.client.post(reverse("index"), {"email": "foo@example.com"},
follow=True,
HTTP_USER_AGENT="foo-agent",
@ -26,3 +26,8 @@ class SignupViewTest(TestCase):
self.assertEqual(obj.anonymized_ip, "127.0.0.0")
self.assertEqual(obj.user_agent, "foo-agent")
self.assertEqual(obj.referrer, "example.org/good-place")
def test_signup_badmail(self):
resp = self.client.post(reverse("index"), {"email": "x@x.x"})
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, "Enter a valid email address.")

View File

@ -33,7 +33,7 @@ def index(request):
s = Signup(
email=request.POST.get("email"),
anonymized_ip=anonymous_ip,
user_agent=request.META['HTTP_USER_AGENT'],
user_agent=request.META.get('HTTP_USER_AGENT', ''),
geoip=geoip,
referrer=request.META.get('HTTP_REFERRER', ''),
)
@ -41,9 +41,8 @@ def index(request):
try:
s.clean_fields()
except ValidationError as e:
print(e)
return render(request, "signup/index.html",
{"error_message": e.message})
{"error_message": ", ".join(e.messages)})
logging.info("registering email={}".format(request.POST.get("email")))
try: