Ejemplo n.º 1
0
 def create_member(self):
     attrs = self.member_attrs.copy()
     # unique email and username for this test run
     id = "%f" % time.time()
     dot = id.rindex('.')
     id = id[dot - 7:dot] + id[dot+1:dot+4]
     attrs['username'] = '******' % id
     attrs['email'] = "*****@*****.**" % id
     member = Member(**attrs)
     member.set_password('password')
     member.save()
     return member
Ejemplo n.º 2
0
 def create_member_partial(cls, commit=True):
     attrs = cls.member_attrs.copy()
     del attrs['gender']
     # unique email and username for this test run
     id = "%f" % time.time()
     dot = id.rindex('.')
     id = id[dot - 7:dot] + id[dot+1:dot+4]
     attrs['username'] = '******' % id
     attrs['email'] = "*****@*****.**" % id
     attrs['mobile_number'] = id
     member = Member(**attrs)
     member.set_password('password')
     if commit:
         member.save()
     return member
Ejemplo n.º 3
0
    def authenticate(self, username=None, password=None):
        obj = None

        for klass, fieldnames in self._authentication_chain:
            for fieldname in fieldnames:
                try:
                    obj = klass.objects.get(**{fieldname: username})
                except klass.DoesNotExist:
                    pass
                else:
                    break
            if obj is not None:
                break

        if obj is None:
            # try to log in via Neo
            consumer_id = authenticate_neo(username, password)
            if consumer_id:
                # create the member using data from Neo
                consumer = api.get_consumer(consumer_id, username, password)
                wrapper = ConsumerWrapper(consumer=consumer)
                attrs = dict((k, getattr(wrapper, k)) for k in NEO_ATTR)
                attrs.update(wrapper.address)
                member = Member(**attrs)
                # don't want save method to attempt to create a consumer
                member.need_to_clean_member = False
                member.consumer_id = consumer_id
                member.save()
                return member
            return None

        # Obj is an instance of either user or a subclass of user, or else a
        # profile.
        if isinstance(obj, User):
            user = obj
        else:
            user = obj.user

        # Authenticate via Neo instead of Django
        consumer_id = authenticate_neo(user.username, password)
        if consumer_id:
            assert NeoProfile.objects.get(consumer_id=consumer_id).user.id == user.id
            return user

        return None
Ejemplo n.º 4
0
 def test_entry_export(self):
     comp = Competition.objects.create(
         title="Test Comp", start_date=timezone.now(), end_date=timezone.now() + timedelta(hours=1)
     )
     member = Member(username="******")
     member.first_name = member.username
     member.set_password("password")
     member.is_staff = True
     member.save()
     CompetitionEntry.objects.create(competition=comp, user=member)
     self.client.login(username=member.username, password="******")
     response = self.client.get(reverse("admin:competition-csv-export"))
     self.assertContains(response, member.username)
     self.assertNotContains(response, "None")
Ejemplo n.º 5
0
                'login_alias': login_alias.encode('utf-8'),
                'password': password.encode('utf-8')
            })
        last_username = member.username.lower()

        elem = etree_from_gds(wrapper.consumer)
        elem.attrib['recordNumber'] = str(i)

        if password_callback is not None:
            new_password = password_callback(member)
            if new_password is not None:
                # Set (or replace) the password.
                password_path.setattr(elem, new_password)
                objectify.deannotate(password_path(elem), cleanup_namespaces=True)
            elif password_path.hasattr(elem):
                # Clear the existing password element, if one exists.
                old_password = password_path(elem)
                old_password.getparent().remove(old_password)

        output.write(etree.tostring(elem, pretty_print=pretty_print))
        output.write('\n')
    output.write('</Consumers>\n')


'''
Patch Member
'''
Member.save = save_member
Member.full_clean = clean_member
Member.add_to_class('objects', NeoMemberManager())