Exemplo n.º 1
0
def autocreate_username(candidate, tries=1):
    """Returns a unique valid username."""
    max_tries = settings.MAX_GEN_USERNAME_TRIES
    from amo.utils import slugify, SLUG_OK
    make_u = partial(slugify, ok=SLUG_OK, lower=True, spaces=False,
                     delimiter='-')
    adjusted_u = make_u(candidate)
    if tries > 1:
        adjusted_u = '%s%s' % (adjusted_u, tries)
    if (BlacklistedName.blocked(adjusted_u) or adjusted_u == ''
            or tries > max_tries or len(adjusted_u) > 255):
        log.info('username blocked, empty, max tries reached, or too long;'
                 ' username=%s; max=%s' % (adjusted_u, max_tries))
        return autocreate_username(uuid.uuid4().hex[0:15])
    if UserProfile.objects.filter(username=adjusted_u).count():
        return autocreate_username(candidate, tries=tries + 1)
    return adjusted_u
Exemplo n.º 2
0
 def test_blocked(self):
     eq_(BlacklistedName.blocked('IE6Fan'), True)
     eq_(BlacklistedName.blocked('testo'), False)
Exemplo n.º 3
0
 def clean_name(self):
     name = self.cleaned_data['name']
     if BlacklistedName.blocked(name):
         raise forms.ValidationError(_('This name cannot be used.'))
     return name
Exemplo n.º 4
0
 def test_blocked(self):
     eq_(BlacklistedName.blocked('IE6Fan'), True)
     eq_(BlacklistedName.blocked('IE6fantastic'), True)
     eq_(BlacklistedName.blocked('IE6'), False)
     eq_(BlacklistedName.blocked('testo'), False)
Exemplo n.º 5
0
 def clean_name(self):
     name = self.cleaned_data['name']
     if BlacklistedName.blocked(name):
         raise forms.ValidationError(_('This name cannot be used.'))
     return name