コード例 #1
0
def validate_username_for_rename_person(username, person):
    """ Validate the new username to rename a person. If the username is
    invalid or in use, raises :py:exc:`UsernameInvalid` or
    :py:exc:`UsernameTaken`.

    :param username: Username to validate.
    :param person: We exclude this person when checking for duplicates.
    """

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username) \
        .exclude(pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken by an existing person.'))

    # Check for existing accounts not owned by person.
    # If there is a conflicting account owned by person it doesn't matter.

    count = Account.objects.filter(username__exact=username) \
        .exclude(person=person).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken by an existing account.'))

    # Check person datastore, in case username created outside Karaage.

    if global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))

    # Check account datastore, in case username created outside Karaage.

    for mc in MachineCategory.objects.all():
        # If there is an active account on this MC and we own it, it doesn't
        # matter
        count = Account.objects.filter(
            username__exact=username,
            person=person,
            machine_category=mc,
            date_deleted__isnull=True).count()
        if count == 0 and machine_category_account_exists(username, mc):
            raise UsernameTaken(
                six.u('Username is already in external account datastore.'))
コード例 #2
0
def validate_username_for_rename_person(username, person):
    """ Validate the new username to rename a person. If the username is
    invalid or in use, raises :py:exc:`UsernameInvalid` or
    :py:exc:`UsernameTaken`.

    :param username: Username to validate.
    :param person: We exclude this person when checking for duplicates.
    """

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username) \
        .exclude(pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken by an existing person.'))

    # Check for existing accounts not owned by person.
    # If there is a conflicting account owned by person it doesn't matter.

    count = Account.objects.filter(username__exact=username) \
        .exclude(person=person).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken by an existing account.'))

    # Check person datastore, in case username created outside Karaage.

    if global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))

    # Check account datastore, in case username created outside Karaage.

    for mc in MachineCategory.objects.all():
        # If there is an active account on this MC and we own it, it doesn't
        # matter
        count = Account.objects.filter(username__exact=username,
                                       person=person,
                                       machine_category=mc,
                                       date_deleted__isnull=True).count()
        if count == 0 and machine_category_account_exists(username, mc):
            raise UsernameTaken(
                six.u('Username is already in external account datastore.'))
コード例 #3
0
def validate_username_for_new_person(username):
    """ Validate the new username for a new person. If the username is invalid
    or in use, raises :py:exc:`UsernameInvalid` or :py:exc:`UsernameTaken`.

    :param username: Username to validate.
    """

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check for existing accounts

    count = Account.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check person datastore, in case username created outside Karaage.

    if global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))

    # Check account datastore, in case username created outside Karaage.

    for mc in MachineCategory.objects.all():
        if machine_category_account_exists(username, mc):
            raise UsernameTaken(
                six.u('Username is already in external account datastore.'))

    return username
コード例 #4
0
def validate_username_for_new_account(person, username):
    """ Validate the new username for a new account. If the username is invalid
    or in use, raises :py:exc:`UsernameInvalid` or :py:exc:`UsernameTaken`.

    :param person: Owner of new account.
    :param username: Username to validate.
    """

    # This is much the same as validate_username_for_new_person, except
    # we don't care if the username is used by the person owning the account

    # is the username valid?

    validate_username(username)

    # Check for existing people

    query = Person.objects.filter(username__exact=username)
    count = query.exclude(pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check for existing accounts not belonging to this person

    query = Account.objects.filter(username__exact=username)
    count = query.exclude(person__pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check person datastore, in case username created outside Karaage.
    # Make sure we don't count the entry for person.

    query = Person.objects.filter(username__exact=username)
    count = query.filter(pk=person.pk).count()
    if count == 0 and global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))
コード例 #5
0
def validate_username_for_new_person(username):
    """ Validate the new username for a new person. If the username is invalid
    or in use, raises :py:exc:`UsernameInvalid` or :py:exc:`UsernameTaken`.

    :param username: Username to validate.
    """

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken. Please choose another. '
                  'If this was the name of your old account please email %s') %
            settings.ACCOUNTS_EMAIL)

    # Check for existing accounts

    count = Account.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken. Please choose another. '
                  'If this was the name of your old account please email %s') %
            settings.ACCOUNTS_EMAIL)

    # Check person datastore, in case username created outside Karaage.

    if global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))

    # Check account datastore, in case username created outside Karaage.

    for mc in MachineCategory.objects.all():
        if machine_category_account_exists(username, mc):
            raise UsernameTaken(
                six.u('Username is already in external account datastore.'))

    return username
コード例 #6
0
def validate_username_for_new_account(person, username):
    """ Validate the new username for a new account. If the username is invalid
    or in use, raises :py:exc:`UsernameInvalid` or :py:exc:`UsernameTaken`.

    :param person: Owner of new account.
    :param username: Username to validate.
    """

    # This is much the same as validate_username_for_new_person, except
    # we don't care if the username is used by the person owning the account

    # is the username valid?

    validate_username(username)

    # Check for existing people

    query = Person.objects.filter(username__exact=username)
    count = query.exclude(pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken. Please choose another. '
                  'If this was the name of your old account please email %s') %
            settings.ACCOUNTS_EMAIL)

    # Check for existing accounts not belonging to this person

    query = Account.objects.filter(username__exact=username)
    count = query.exclude(person__pk=person.pk).count()
    if count >= 1:
        raise UsernameTaken(
            six.u('The username is already taken. Please choose another. '
                  'If this was the name of your old account please email %s') %
            settings.ACCOUNTS_EMAIL)

    # Check person datastore, in case username created outside Karaage.
    # Make sure we don't count the entry for person.

    query = Person.objects.filter(username__exact=username)
    count = query.filter(pk=person.pk).count()
    if count == 0 and global_person_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))