signup: fix bugs
This commit is contained in:
parent
47d103e08c
commit
93653ee1bd
@ -5,7 +5,7 @@ class Signup(models.Model):
|
|||||||
email = models.EmailField()
|
email = models.EmailField()
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
anonymized_ip = models.GenericIPAddressField()
|
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)
|
geoip = models.JSONField(null=True, blank=True)
|
||||||
referrer = models.CharField(max_length=255, blank=True)
|
referrer = models.CharField(max_length=255, blank=True)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class SignupViewTest(TestCase):
|
|||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertContains(resp, "Hosted Syncthing")
|
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"},
|
resp = self.client.post(reverse("index"), {"email": "foo@example.com"},
|
||||||
follow=True,
|
follow=True,
|
||||||
HTTP_USER_AGENT="foo-agent",
|
HTTP_USER_AGENT="foo-agent",
|
||||||
@ -26,3 +26,8 @@ class SignupViewTest(TestCase):
|
|||||||
self.assertEqual(obj.anonymized_ip, "127.0.0.0")
|
self.assertEqual(obj.anonymized_ip, "127.0.0.0")
|
||||||
self.assertEqual(obj.user_agent, "foo-agent")
|
self.assertEqual(obj.user_agent, "foo-agent")
|
||||||
self.assertEqual(obj.referrer, "example.org/good-place")
|
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.")
|
||||||
|
@ -33,7 +33,7 @@ def index(request):
|
|||||||
s = Signup(
|
s = Signup(
|
||||||
email=request.POST.get("email"),
|
email=request.POST.get("email"),
|
||||||
anonymized_ip=anonymous_ip,
|
anonymized_ip=anonymous_ip,
|
||||||
user_agent=request.META['HTTP_USER_AGENT'],
|
user_agent=request.META.get('HTTP_USER_AGENT', ''),
|
||||||
geoip=geoip,
|
geoip=geoip,
|
||||||
referrer=request.META.get('HTTP_REFERRER', ''),
|
referrer=request.META.get('HTTP_REFERRER', ''),
|
||||||
)
|
)
|
||||||
@ -41,9 +41,8 @@ def index(request):
|
|||||||
try:
|
try:
|
||||||
s.clean_fields()
|
s.clean_fields()
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
print(e)
|
|
||||||
return render(request, "signup/index.html",
|
return render(request, "signup/index.html",
|
||||||
{"error_message": e.message})
|
{"error_message": ", ".join(e.messages)})
|
||||||
|
|
||||||
logging.info("registering email={}".format(request.POST.get("email")))
|
logging.info("registering email={}".format(request.POST.get("email")))
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user