Exemplo n.º 1
0
    def post(self, request):
        username = request.POST.get('username', '').strip().lower()
        domain = request.POST.get('domain', '').strip().lower()
        log.info('Checking %s@%s for existence.', username, domain)

        cache_key = 'exists_%s@%s' % (username, domain)
        exists = cache.get(cache_key)
        if exists is True:
            return HttpResponse('')
        elif exists is False:
            return HttpResponse('', status=404)

        # Check if the user exists in the database
        try:
            User.objects.get_user(username, domain)
            cache.set(cache_key, True, 30)
            return HttpResponse('')
        except User.DoesNotExist:
            pass

        # Check if the user exists in the backend
        if backend.exists(username, domain):
            cache.set(cache_key, True, 30)
            return HttpResponse('')
        else:
            cache.set(cache_key, False, 30)
            return HttpResponse('', status=404)
Exemplo n.º 2
0
 def clean(self):
     data = super(RegistrationForm, self).clean()
     if data.get('jid'):  # implies username/domain also present
         if User.objects.filter(jid=data['jid']).exists() \
                 or backend.exists(username=data['username'], domain=data['domain']):
             self._username_status = 'taken'
             raise forms.ValidationError(_("User already exists."))
     return data
Exemplo n.º 3
0
 def clean(self):
     data = super(RegistrationForm, self).clean()
     if data.get('jid'):  # implies username/domain also present
         if User.objects.filter(jid=data['jid']).exists() \
                 or backend.exists(username=data['username'], domain=data['domain']):
             self._username_status = 'taken'
             raise forms.ValidationError(_("User already exists."))
     return data