diff --git a/helios/models.py b/helios/models.py index 04a7f648d22ae906ca62489dcc9db755c1601c15..af83572e0a42f29743b781af1d7c5bd4bdf0be8f 100644 --- a/helios/models.py +++ b/helios/models.py @@ -1031,7 +1031,10 @@ class Trustee(HeliosModel): @classmethod def get_by_election_and_email(cls, election, email): - return cls.objects.get(election = election, email = email) + try: + return cls.objects.get(election = election, email = email) + except cls.DoesNotExist: + return None @property def datatype(self): diff --git a/helios/tests.py b/helios/tests.py index 26c4df605423db3ada9d8d88ec461cd1c48bbbed..b01729025633b6d0032ea937c9f48bf9af565656 100644 --- a/helios/tests.py +++ b/helios/tests.py @@ -343,8 +343,8 @@ class ElectionBlackboxTests(TestCase): self.assertEquals(response.content, views.ELGAMAL_PARAMS_LD_OBJECT.serialize()) def test_election_bad_trustee(self): - response = self.client.get("/helios/elections/%s/trustees/foobar@bar.com/badsecret" % self.election.uuid) - import pdb; pdb.set_trace() + response = self.client.get("/helios/t/%s/foobar@bar.com/badsecret" % self.election.short_name) + self.assertEquals(response.status_code, 404) def test_get_election_shortcut(self): response = self.client.get("/helios/e/%s" % self.election.short_name, follow=True) diff --git a/helios/views.py b/helios/views.py index b7df7fa243176f4ef1fdf3262a7bf31785344912..80c5497a0d8f7f8bc21d34a67b53d58f4430faeb 100644 --- a/helios/views.py +++ b/helios/views.py @@ -396,9 +396,16 @@ def trustee_login(request, election_short_name, trustee_email, trustee_secret): if election: trustee = Trustee.get_by_election_and_email(election, trustee_email) - if trustee and trustee.secret == trustee_secret: - set_logged_in_trustee(request, trustee) - return HttpResponseRedirect(reverse(trustee_home, args=[election.uuid, trustee.uuid])) + if trustee: + if trustee.secret == trustee_secret: + set_logged_in_trustee(request, trustee) + return HttpResponseRedirect(reverse(trustee_home, args=[election.uuid, trustee.uuid])) + else: + # bad secret, we'll let that redirect to the front page + pass + else: + # no such trustee + raise Http404 return HttpResponseRedirect("/")