Skip to content
Snippets Groups Projects
Commit dfe1074c authored by Ben Adida's avatar Ben Adida
Browse files

fixed logic for password+other elections, mostly

parent 368f7eaa
Branches
Tags
No related merge requests found
......@@ -4,7 +4,7 @@ AUTH_SYSTEMS = {}
import twitter, password, cas, facebook, google, yahoo, linkedin
AUTH_SYSTEMS['twitter'] = twitter
AUTH_SYSTEMS['linkedin'] = linkedin
AUTH_SYSTEMS['password'] = password
#AUTH_SYSTEMS['password'] = password
AUTH_SYSTEMS['cas'] = cas
AUTH_SYSTEMS['facebook'] = facebook
AUTH_SYSTEMS['google'] = google
......
......@@ -56,7 +56,11 @@ def login_box_raw(request, return_url='/', auth_systems = None):
if auth.DEFAULT_AUTH_SYSTEM:
default_auth_system_obj = AUTH_SYSTEMS[auth.DEFAULT_AUTH_SYSTEM]
enabled_auth_systems = auth_systems or auth.ENABLED_AUTH_SYSTEMS
# make sure that auth_systems includes only available and enabled auth systems
if auth_systems != None:
enabled_auth_systems = set(auth_systems).intersection(set(auth.ENABLED_AUTH_SYSTEMS)).intersection(set(AUTH_SYSTEMS.keys()))
else:
enabled_auth_systems = set(auth.ENABLED_AUTH_SYSTEMS).intersection(set(AUTH_SYSTEMS.keys()))
form = password.LoginForm()
......
......@@ -2,7 +2,7 @@
data types for 2011/01 Helios
"""
from helios.datatypes import LDObject, arrayOf
from helios.datatypes import LDObject, arrayOf, DictObject, ListObject
class Trustee(LDObject):
"""
......@@ -26,7 +26,8 @@ class Election(LDObject):
'public_key' : 'pkc/elgamal/PublicKey',
'voting_starts_at': 'core/Timestamp',
'voting_ends_at': 'core/Timestamp',
'frozen_at': 'core/Timestamp'
'frozen_at': 'core/Timestamp',
'questions': '2011/01/Questions',
}
class Voter(LDObject):
......@@ -43,3 +44,6 @@ class EncryptedAnswer(LDObject):
}
class Questions(ListObject, LDObject):
WRAPPED_OBJ = list
......@@ -64,6 +64,7 @@ def get_class(datatype):
except AttributeError:
raise Exception ("no module for %s" % datatype)
dynamic_cls.datatype = datatype
return dynamic_cls
......@@ -189,9 +190,13 @@ class LDObject(object):
else:
val[f] = self.process_value_out(f, self._getattr_wrapped(f))
if complete and self.USE_JSON_LD:
if self.USE_JSON_LD:
if complete:
val['#'] = {'_': 'http://heliosvoting.org/ns#'}
if hasattr(self, 'datatype'):
val['a'] = self.datatype
return val
toJSONDict = toDict
......@@ -298,3 +303,18 @@ def arrayOf(element_type):
return ArrayOfTypedObjects
class DictObject(object):
"when the wrapped object is actually dictionary"
def _getattr_wrapped(self, attr):
return self.wrapped_obj[attr]
def _setattr_wrapped(self, attr, val):
self.wrapped_obj[attr] = val
class ListObject(object):
def loadDataFromDict(self, d):
self.wrapped_obj = d
def toDict(self, complete=False):
return self.wrapped_obj
......@@ -2,7 +2,7 @@
Legacy datatypes for Helios (v3.0)
"""
from helios.datatypes import LDObject, arrayOf
from helios.datatypes import LDObject, arrayOf, DictObject, ListObject
from helios.crypto import elgamal as crypto_elgamal
from helios.workflows import homomorphic
......@@ -13,14 +13,6 @@ class LegacyObject(LDObject):
WRAPPED_OBJ_CLASS = dict
USE_JSON_LD = False
class DictObject(object):
"when the wrapped object is actually dictionary"
def _getattr_wrapped(self, attr):
return self.wrapped_obj[attr]
def _setattr_wrapped(self, attr, val):
self.wrapped_obj[attr] = val
class Election(LegacyObject):
WRAPPED_OBJ_CLASS = homomorphic.Election
FIELDS = ['uuid', 'questions', 'name', 'short_name', 'description', 'voters_hash', 'openreg',
......@@ -188,16 +180,9 @@ class Result(LegacyObject):
def toDict(self, complete=False):
return self.wrapped_obj
class Questions(LegacyObject):
class Questions(ListObject, LegacyObject):
WRAPPED_OBJ = list
def loadDataFromDict(self, d):
self.wrapped_obj = d
def toDict(self, complete=False):
return self.wrapped_obj
class Tally(LegacyObject):
WRAPPED_OBJ_CLASS = homomorphic.Tally
FIELDS = ['tally', 'num_tallied']
......
......@@ -98,7 +98,12 @@ the same account you registered with.
{% endif %}
</p>
{% if show_password %}
{% include "_castconfirm_password.html" %}
{% endif %}
{{login_box|safe}}
<br />
Don't worry, we'll remember your ballot while you log in.
{% endif %}
......
......@@ -567,11 +567,15 @@ def one_election_cast_confirm(request, election):
else:
auth_systems = None
password_only = False
if auth_systems == None or 'password' in auth_systems:
show_password = True
password_login_form = forms.VoterPasswordForm()
if auth_systems == ['password']:
password_only = True
password_login_form = forms.VoterPasswordForm()
else:
password_only = False
show_password = False
password_login_form = None
return_url = reverse(one_election_cast_confirm, args=[election.uuid])
......@@ -581,7 +585,7 @@ def one_election_cast_confirm(request, election):
'login_box': login_box, 'election' : election, 'vote_fingerprint': vote_fingerprint,
'past_votes': past_votes, 'issues': issues, 'voter' : voter,
'status_update_label': status_update_label, 'status_update_message': status_update_message,
'password_only': password_only, 'password_login_form': password_login_form})
'show_password': show_password, 'password_only': password_only, 'password_login_form': password_login_form})
if request.method == "POST":
check_csrf(request)
......
......@@ -3,4 +3,4 @@ dropdb helios
createdb helios
python manage.py syncdb
python manage.py migrate
echo "from auth.models import User; User.update_or_create(user_type='password',user_id='benadida',info={'password':'test'})" | python manage.py shell
\ No newline at end of file
echo "from auth.models import User; User.update_or_create(user_type='google',user_id='ben@adida.net',info={})" | python manage.py shell
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment