From e1fed194bc0db72e2b332d57cc7af46e84ae6e93 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Wed, 29 Sep 2010 09:36:20 -0700
Subject: [PATCH] prevent password users from self-registering and add handling
 of google accounts without firstname/lastname

---
 auth/auth_systems/google.py | 10 +++++++++-
 helios/views.py             |  4 ++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/auth/auth_systems/google.py b/auth/auth_systems/google.py
index 847530b..02953a3 100644
--- a/auth/auth_systems/google.py
+++ b/auth/auth_systems/google.py
@@ -32,7 +32,15 @@ def get_auth_url(request, redirect_url):
 def get_user_info_after_auth(request):
   data = view_helpers.finish_openid(request.session, request.GET, request.session['google_redirect_url'])
 
-  return {'type' : 'google', 'user_id': data['ax']['email'][0], 'name': "%s %s" % (data['ax']['firstname'][0], data['ax']['lastname'][0]), 'info': {}, 'token':{}}
+  email = data['ax']['email'][0]
+
+  # do we have a firstname/lastname?
+  if data['ax'].has_key('firstname') and data['ax'].has_key('lastname'):
+    name = "%s %s" % (data['ax']['firstname'][0], data['ax']['lastname'][0])
+  else:
+    name = email
+
+  return {'type' : 'google', 'user_id': email, 'name': name , 'info': {}, 'token':{}}
     
 def do_logout(user):
   """
diff --git a/helios/views.py b/helios/views.py
index f47b871..d4dad1e 100644
--- a/helios/views.py
+++ b/helios/views.py
@@ -708,6 +708,10 @@ def one_election_questions(request, election):
   return render_template(request, 'election_questions', {'election': election, 'questions_json' : questions_json, 'admin_p': admin_p})
 
 def _check_eligibility(election, user):
+  # prevent password-users from signing up willy-nilly for other elections, doesn't make sense
+  if user.user_type == 'password':
+    return False
+
   return election.user_eligible_p(user)
 
 def _register_voter(election, user):
-- 
GitLab