Ejemplo n.º 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))
Ejemplo n.º 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
Ejemplo n.º 3
0
 def test_identifier_global(self):
     u = User(email='*****@*****.**')
     u.set_password("test")
     u.save()
     self.assertEqual(u.identifier, "*****@*****.**")