Example #1
0
File: forms.py Project: gage/proto
    def clean(self):
        data = self.cleaned_data
        username = data.get('username')
        
        if not self.is_resend and 'username' in data:
            if check_username(username) is False:
                msg = _("This username is not available or already in use.")
                self._errors["username"] = self.error_class([msg])
                del data["username"]

        return data
Example #2
0
File: ajax.py Project: gage/proto
def ajax_check_username(request):
    username = request.POST.get('username')
    rule = re.compile('^[\.\w-]+$')
    try:
        rule.match(username).group()
    except:
        return HttpJsonResponse(success=False)
    if check_username(username) is False:
        return HttpJsonResponse(success=False)
    return HttpJsonResponse()

    
Example #3
0
def validate_username(username):
    if username.startswith('_'):
        raise api_errors.APIException(api_errors.ERROR_REGISTRATION_INVALID_USERNAME)
    #Check if the username format is valid
    if not username or not USERNAME_FORMAT.match(username):
        raise api_errors.APIException(api_errors.ERROR_REGISTRATION_INVALID_USERNAME)

    if " " in username or "-" in username:
        raise api_errors.APIException(api_errors.ERROR_REGISTRATION_INVALID_USERNAME)

    #Check if the username is available
    if not check_username(username):
        raise api_errors.APIException(api_errors.ERROR_REGISTRATION_USERNAME_UNAVAILABLE)
    return True