Ejemplo n.º 1
0
def process_username(username, domain):
    from corehq.apps.users.forms import (clean_mobile_worker_username,
        get_mobile_worker_max_username_length)

    max_length = get_mobile_worker_max_username_length(domain)

    return clean_mobile_worker_username(
        domain,
        username,
        name_too_long_message=get_message(MSG_USERNAME_TOO_LONG, context=(username, max_length)),
        name_exists_message=get_message(MSG_DUPLICATE_USERNAME, context=(username,))
    )
Ejemplo n.º 2
0
def process_username(username, domain):
    from corehq.apps.users.forms import (clean_mobile_worker_username,
        get_mobile_worker_max_username_length)

    max_length = get_mobile_worker_max_username_length(domain)

    return clean_mobile_worker_username(
        domain,
        username,
        name_too_long_message=get_message(MSG_USERNAME_TOO_LONG, context=(username, max_length)),
        name_exists_message=get_message(MSG_DUPLICATE_USERNAME, context=(username,))
    )
Ejemplo n.º 3
0
def get_new_username_and_id(domain, attempts_remaining=3):
    if attempts_remaining <= 0:
        raise AssertionError(
            "3 IssuerIds were created, but they all corresponded to existing "
            "users.  Are there a bunch of users with usernames matching "
            "possible compressed ids?  Better investigate.")

    user_id = uuid.uuid4().hex
    issuer_id, created = IssuerId.objects.get_or_create(domain=domain, user_id=user_id)
    compressed_issuer_id = compress_nikshay_id(issuer_id.pk, 3)
    try:
        return clean_mobile_worker_username(domain, compressed_issuer_id), user_id
    except forms.ValidationError:
        issuer_id.delete()
        return get_new_username_and_id(domain, attempts_remaining - 1)
Ejemplo n.º 4
0
def generate_username(domain, first_name, last_name):
    if first_name and last_name:
        username = '******' % (first_name, last_name)
    elif first_name:
        username = first_name
    else:
        username = '******' + uuid.uuid4().hex[:8]

    username = re.sub('[^\w]', '', username)
    username = username[:40]

    if CouchUser.username_exists(format_username(username, domain)):
        for i in range(2, 10000):
            tmp_username = '******' % (username, i)
            if not CouchUser.username_exists(format_username(tmp_username, domain)):
                username = tmp_username
                break

    # Perform standard validation
    return clean_mobile_worker_username(domain, username)
Ejemplo n.º 5
0
def generate_username(domain, first_name, last_name):
    if first_name and last_name:
        username = u'%s_%s' % (first_name, last_name)
    elif first_name:
        username = first_name
    else:
        username = '******' + uuid.uuid4().hex[:8]

    username = re.sub('[^\w]', '', username)
    username = username[:40]

    if CouchUser.username_exists(format_username(username, domain)):
        for i in range(2, 10000):
            tmp_username = u'%s-%s' % (username, i)
            if not CouchUser.username_exists(format_username(tmp_username, domain)):
                username = tmp_username
                break

    # Perform standard validation
    return clean_mobile_worker_username(domain, username)