Exemplo n.º 1
0
  def generate_password(self, length=10):
    if self.voter_password:
      raise Exception(_('password already exists'))

    # CSV_VOTERS_PASSWORD_SIMPLIFIED means password generated with 6 letters and just in lowercase.
    if settings.CSV_VOTERS_PASSWORD_SIMPLIFIED:
      length = 06
      self.voter_password = heliosutils.random_string(length, alphabet='abcdefghijkmnopqrstuvwxyz').strip()
    else:
      self.voter_password = heliosutils.random_string(length, alphabet='abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789').strip()
Exemplo n.º 2
0
    def generate_password(self, length=10):
        if self.voter_password:
            raise Exception("password already exists")

        self.voter_password = heliosutils.random_string(
            length, alphabet="abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789"
        )
Exemplo n.º 3
0
    def generate_password(self, length=10):
        if self.voter_password:
            raise Exception("password already exists")

        self.voter_password = utils.random_string(
            length,
            alphabet='abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
        )
Exemplo n.º 4
0
    def process(self):
        self.processing_started_at = datetime.datetime.utcnow()
        self.save()

        election = self.election
        reader = unicode_csv_reader(open(self.voter_file.path, "rU"))

        last_alias_num = election.last_alias_num

        num_voters = 0
        voter_uuids = []
        for voter in reader:
            # bad line
            if len(voter) < 1:
                continue

            num_voters += 1
            voter_id = voter[0]
            name = voter_id
            email = voter_id

            if len(voter) > 1:
                email = voter[1]

            if len(voter) > 2:
                name = voter[2]

            # create the user
            user = User.update_or_create(
                user_type="password",
                user_id=voter_id,
                info={"password": heliosutils.random_string(10), "email": email, "name": name},
            )
            user.save()

            # does voter for this user already exist
            voter = Voter.get_by_election_and_user(election, user)

            # create the voter
            if not voter:
                voter_uuid = str(uuid.uuid4())
                voter = Voter(uuid=voter_uuid, voter_type="password", voter_id=voter_id, name=name, election=election)
                voter_uuids.append(voter_uuid)
                voter.save()

        if election.use_voter_aliases:
            voter_alias_integers = range(last_alias_num + 1, last_alias_num + 1 + num_voters)
            random.shuffle(voter_alias_integers)
            for i, voter_uuid in enumerate(voter_uuids):
                voter = Voter.get_by_election_and_uuid(election, voter_uuid)
                voter.alias = "V%s" % voter_alias_integers[i]
                voter.save()

        self.num_voters = num_voters
        self.processing_finished_at = datetime.datetime.utcnow()
        self.save()

        return num_voters
Exemplo n.º 5
0
 def put(self, *args, **kwargs):
   """
   override this just to get a hook
   """
   # not saved yet?
   if not self.secret:
     self.secret = heliosutils.random_string(12)
     
   super(Trustee, self).put(*args, **kwargs)
Exemplo n.º 6
0
 def save(self, *args, **kwargs):
   """
   override this just to get a hook
   """
   # not saved yet?
   if not self.secret:
     self.secret = heliosutils.random_string(12)
     self.election.append_log("Trustee %s added" % self.name)
     
   super(Trustee, self).save(*args, **kwargs)
Exemplo n.º 7
0
 def save(self, *args, **kwargs):
   """
   override this just to get a hook
   """
   # not saved yet?
   if not self.secret:
     self.secret = heliosutils.random_string(12)
     self.election.append_log("Trustee %s added" % self.name)
     
   super(Trustee, self).save(*args, **kwargs)
Exemplo n.º 8
0
def process_csv_file(election, f):
    reader = unicode_csv_reader(f)

    num_voters = 0
    for voter in reader:
        # bad line
        if len(voter) < 1:
            continue

        num_voters += 1
        voter_id = voter[0]
        name = voter_id
        email = voter_id
        peso = voter_id

        if len(voter) > 1:
            email = voter[1]

        if len(voter) > 2:
            name = voter[2]

        if len(voter) > 3:
            peso = voter[3]

        # create the user
        user = User.update_or_create(user_type='password',
                                     user_id=voter_id,
                                     info={
                                         'password':
                                         helios_utils.random_string(10),
                                         'email': email,
                                         'name': name,
                                         'peso': peso
                                     })
        user.save()

        # does voter for this user already exist
        voter = Voter.get_by_election_and_user(election, user)

        # create the voter
        if not voter:
            voter_uuid = str(uuid.uuid1())
            voter = Voter(uuid=voter_uuid,
                          voter_type='password',
                          voter_id=voter_id,
                          name=name,
                          election=election,
                          voter_peso=peso)
            Voter.setVoter_peso(peso)
            voter.save()

    return num_voters
Exemplo n.º 9
0
def process_csv_file(election, f):
    reader = unicode_csv_reader(f)

    num_voters = 0
    for voter in reader:
        # bad line
        if len(voter) < 1:
            continue

        num_voters += 1
        voter_id = voter[0]
        name = voter_id
        email = voter_id

        if len(voter) > 1:
            email = voter[1]

        if len(voter) > 2:
            name = voter[2]

        # create the user
        user = User.update_or_create(
            user_type="password",
            user_id=voter_id,
            info={
                "password": helios_utils.random_string(10),
                "email": email,
                "name": name,
            },
        )
        user.save()

        # does voter for this user already exist
        voter = Voter.get_by_election_and_user(election, user)

        # create the voter
        if not voter:
            voter_uuid = str(uuid.uuid1())
            voter = Voter(
                uuid=voter_uuid,
                voter_type="password",
                voter_id=voter_id,
                name=name,
                election=election,
            )
            voter.save()

    return num_voters
Exemplo n.º 10
0
def password_register(request):
  '''
  Registers an user, sending him an email with his new password, therefore
  checking that he entered the correct email.
  '''
  error = None

  if 'password' not in settings.AUTH_ENABLED_AUTH_SYSTEMS:
    return redirect('/')

  if request.method == "GET":
    form = RegisterForm()
  else:
    form = RegisterForm(request.POST)
    if not form.is_valid():
      error = _("Please fix the errors in the form.")
    elif User.objects.filter(user_id=request.POST['email']).exists():
      error = _("An user with the given email address is already registered.")
    else:
      try:
        new_user = User.objects.create(user_type='password',user_id=request.POST['email'],
          name=request.POST['name'], info={'name':request.POST['name'],
          'email':request.POST['email'],'password': random_string(10)})
      except:
        error = _("User already exists.")
        return render_template(request, 'password/register', {'form': form, 'error': error})
      new_user.save()

      mail_body = _("""

Hi %(username)s, you just registered into %(site_title)s. Here are your login details:

Your username: %(userid)s
Your password: %(password)s

--
%(site_title)s
""") % dict(usernmae=new_user.info['name'], site_title=settings.SITE_TITLE, userid=new_user.user_id, password=new_user.info['password'])
      mail_title = _("Welcome to %(site_title)s, %(username)s") % dict(site_title=settings.SITE_TITLE, username=new_user.info['name'])

      send_mail(mail_title, mail_body, settings.SERVER_EMAIL, ["%s <%s>" % (new_user.info['name'], new_user.info['email'])], fail_silently=False)


      messages.add_message(request, messages.SUCCESS, _('You have just been registered in %s. Check your email for your login details.') % settings.SITE_TITLE)

      return redirect('/')

  return render_template(request, 'password/register', {'form': form, 'error': error})
Exemplo n.º 11
0
def process_csv_file(election, f):
    reader = unicode_csv_reader(f)

    num_voters = 0
    for voter in reader:
        # bad line
        if len(voter) < 1:
            continue

        num_voters += 1
        voter_id = voter[0]
        name = voter_id
        email = voter_id

        if len(voter) > 1:
            email = voter[1]

        if len(voter) > 2:
            name = voter[2]

        # create the user
        user = User.update_or_create(user_type='password', user_id=voter_id, info={
                                     'password': helios_utils.random_string(10), 'email': email, 'name': name})
        user.save()

        # does voter for this user already exist
        voter = Voter.get_by_election_and_user(election, user)

        # create the voter
        if not voter:
            voter_uuid = str(uuid.uuid1())
            voter = Voter(uuid=voter_uuid, voter_type='password',
                          voter_id=voter_id, name=name, election=election)
            voter.save()

    return num_voters
Exemplo n.º 12
0
def generate_password(length=10):
    return heliosutils.random_string(length, alphabet='abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
Exemplo n.º 13
0
 def generate_password(self, length=10):
   if self.voter_password:
     raise Exception(_("password already exists"))
   
   self.voter_password = heliosutils.random_string(length)
Exemplo n.º 14
0
  def process(self):
    self.processing_started_at = datetime.datetime.utcnow()
    self.save()

    election = self.election
    reader = unicode_csv_reader(self.voter_file)
    
    num_voters_before = election.num_voters

    num_voters = 0
    voter_uuids = []
    for voter in reader:
      # bad line
      if len(voter) < 1:
        continue
    
      num_voters += 1
      voter_id = voter[0]
      name = voter_id
      email = voter_id
    
      if len(voter) > 1:
        email = voter[1]
    
      if len(voter) > 2:
        name = voter[2]
    
      # create the user
      user = User.update_or_create(user_type='password', user_id=voter_id, info = {'password': heliosutils.random_string(10), 'email': email, 'name': name})
      user.save()
    
      # does voter for this user already exist
      voter = Voter.get_by_election_and_user(election, user)
    
      # create the voter
      if not voter:
        voter_uuid = str(uuid.uuid1())
        voter = Voter(uuid= voter_uuid, voter_type = 'password', voter_id = voter_id, name = name, election = election)
        voter_uuids.append(voter_uuid)
        voter.save()

    if election.use_voter_aliases:
      voter_alias_integers = range(num_voters_before+1, num_voters_before+1+num_voters)
      random.shuffle(voter_alias_integers)
      for i, voter_uuid in enumerate(voter_uuids):
        voter = Voter.get_by_election_and_uuid(election, voter_uuid)
        voter.alias = 'V%s' % voter_alias_integers[i]
        voter.save()

    self.num_voters = num_voters
    self.processing_finished_at = datetime.datetime.utcnow()
    self.save()

    return num_voters
Exemplo n.º 15
0
def process_csv_file(election, f):
    reader = unicode_csv_reader(f)
    
    num_voters = 0
    for voter in reader:
      # bad line
      if len(voter) < 1:
        continue
    
      num_voters += 1
      voter_id = voter[0]
      name = voter_id
      email = voter_id
    
      if len(voter) > 1:
        email = voter[1]
    
      if len(voter) > 2:
        name = voter[2]
    
      # create the user
      user = User.update_or_create(user_type='dnie', user_id=voter_id, info = {'password': helios_utils.random_string(10), 'email': email, 'name': name})
      user.save()
    
      print 1/0
      print 'hola'
      logger.debug(user)
      logger.debug(user.name)
      try:
        logger.debug(user.id)
      except:
        logger.debug('excepcion con el user.id')
      # does voter for this user already exist
      voter = Voter.get_by_election_and_user(election, user)
    
      # create the voter
      if not voter:
        voter_uuid = str(uuid.uuid1())
        voter = Voter(uuid= voter_uuid, voter_type = 'dnie', voter_id = voter_id, name = name, election = election)
        voter.save()

    return num_voters
Exemplo n.º 16
0
def voters_upload(request, election):
  """
  Upload a CSV of password-based voters with
  voter_id, email, name
  
  name and email are needed only if voter_type is static
  """
  if request.method == "GET":
    return render_template(request, 'voters_upload', {'election': election})
    
  if request.method == "POST":
    voters_csv_lines = request.POST['voters_csv'].split("\n")
    reader = csv.reader(voters_csv_lines)

    for voter in reader:

      # bad line
      if len(voter) < 1:
        continue

      voter_id = voter[0]
      name = voter_id
      email = voter_id

      #[[OP: default weight]]
      weight = 1
      
      if len(voter) > 1:
        email = voter[1]
      
      if len(voter) > 2:
        name = voter[2]

      # [[OP: parsing voter weight]]
      if len(voter) > 3:
        weight = int(voter[3])
        
      # create the user
      user = User.update_or_create(user_type='password', user_id=voter_id, info = {'password': helios_utils.random_string(10), 'email': email, 'name': name})
      user.put()
      
      # does voter for this user already exist
      voter = Voter.get_by_election_and_user(election, user)
      
      # create the voter
      if not voter:
        voter_uuid = str(uuid.uuid1())
        voter = Voter(uuid= voter_uuid, voter_type = 'password', voter_id = voter_id, name = name, election = election)
        # [[OP: adding weight field]]
        voter.weight = weight
        voter.put()
    
    return HttpResponse("OK")
Exemplo n.º 17
0
    def generate_password(self, length=10):
        if self.voter_password:
            raise Exception("password already exists")

        self.voter_password = heliosutils.random_string(length)