diff --git a/app/signup/models.py b/app/signup/models.py index 656053f..2b671fa 100644 --- a/app/signup/models.py +++ b/app/signup/models.py @@ -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) diff --git a/app/signup/tests.py b/app/signup/tests.py index d32cb2a..ae85047 100644 --- a/app/signup/tests.py +++ b/app/signup/tests.py @@ -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.") diff --git a/app/signup/views.py b/app/signup/views.py index d9687e0..c71816c 100644 --- a/app/signup/views.py +++ b/app/signup/views.py @@ -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: