Пример #1
0
 def test_identifier_local(self):
     o = Organizer.objects.create(name='Dummy', slug='dummy')
     event = Event.objects.create(
         organizer=o, name='Dummy', slug='dummy',
         date_from=now(),
     )
     u = User(event=event, username='******')
     u.set_password("test")
     u.save()
     self.assertEqual(u.identifier, "%s@%s.event.pretix" % (u.username.lower(), event.id))
Пример #2
0
 def form_authenticate(self, request, form_data):
     from pretix.base.models import User
     password = form_data['password']
     template_data = {
         p: escape_filter_chars(form_data[p])
         for p in self.placeholders
     }
     filter = self.search_filter_template.format_map(template_data)
     if not self.connection.search(
             self.search_base, filter, attributes=[self.email_attr]):
         # user not found
         return None
     res = self.connection.response
     if len(res) != 1:
         # could not uniquely identify user
         logger.warn(
             "Could not uniquely identify user. Check your search_filter")
         return None
     dn = res[0]['dn']
     emails = res[0]['attributes'][self.email_attr]
     # handle email being a single-valued attribute
     if isinstance(emails, str):
         emails = [emails]
     if len(emails) != 1:
         # could not uniquely identify user email
         logger.warn("Could not uniquely identify user email")
         return None
     email = emails[0]
     try:
         success = self.connection.rebind(user=dn, password=password)
     except:  # noqa
         success = False
     self.connection.rebind(self.config.get('ldap', 'bind_dn'),
                            self.config.get('ldap', 'bind_password'))
     if not success:
         # wrong password
         return None
     try:
         user = User.objects.get(email=email)
         if user.auth_backend == self.identifier:
             return user
         else:
             # user already registered with different backend
             return None
     except User.DoesNotExist:
         # user does not exist yet -> create new
         user = User(email=email)
         user.auth_backend = self.identifier
         user.save()
         return user
Пример #3
0
 def clean_password(self):
     password1 = self.cleaned_data.get('password', '')
     user = User(email=self.cleaned_data.get('email'))
     if validate_password(password1, user=user) is not None:
         raise forms.ValidationError(_(password_validators_help_texts()),
                                     code='pw_invalid')
     return password1
Пример #4
0
def multiexport(self, organizer: Organizer, user: User, fileid: str, provider: str, form_data: Dict[str, Any]) -> None:
    def set_progress(val):
        if not self.request.called_directly:
            self.update_state(
                state='PROGRESS',
                meta={'value': val}
            )

    file = CachedFile.objects.get(id=fileid)
    with language(user.locale), override(user.timezone):
        allowed_events = user.get_events_with_permission('can_view_orders')

        events = allowed_events.filter(pk__in=form_data.get('events'))
        responses = register_multievent_data_exporters.send(organizer)

        for receiver, response in responses:
            if not response:
                continue
            ex = response(events, set_progress)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.')
                    )
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename), ContentFile(data))
                file.save()
    return file.pk
Пример #5
0
def multiexport(organizer: Organizer, user: User, fileid: str, provider: str,
                form_data: Dict[str, Any]) -> None:
    file = CachedFile.objects.get(id=fileid)
    with language(user.locale), override(user.timezone):
        allowed_events = user.get_events_with_permission('can_view_orders')

        events = allowed_events.filter(pk__in=form_data.get('events'))
        responses = register_multievent_data_exporters.send(organizer)

        for receiver, response in responses:
            ex = response(events)
            if ex.identifier == provider:
                d = ex.render(form_data)
                if d is None:
                    raise ExportError(
                        gettext('Your export did not contain any data.'))
                file.filename, file.type, data = d
                file.file.save(cachedfile_name(file, file.filename),
                               ContentFile(data))
                file.save()
    return file.pk
Пример #6
0
 def test_identifier_global(self):
     u = User(email='*****@*****.**')
     u.set_password("test")
     u.save()
     self.assertEqual(u.identifier, "*****@*****.**")