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.
10034
def validate_username_for_new_account(person, username):
    

    # 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 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 account_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external personal datastore.'))
358920
def account_id(self, account_id):
        
        if account_id is None:
            raise ValueError("Invalid value for `account_id`, must not be `None`")
        if account_id is not None and len(account_id) > 250:
            raise ValueError("Invalid value for `account_id`, length must be less than or equal to `250`")
        if account_id is not None and len(account_id) < 1:
            raise ValueError("Invalid value for `account_id`, length must be greater than or equal to `1`")

        self._account_id = account_id
1139968
def validate_username(username):
    

    # Check username looks ok

    if not username.islower():
        raise UsernameInvalid(six.u('Username must be all lowercase'))
    if len(username) < 2:
        raise UsernameInvalid(six.u('Username must be at least 2 characters'))
    if not username_re.search(username):
        raise UsernameInvalid(settings.USERNAME_VALIDATION_ERROR_MSG)

    return username
1235309
def get_user(self, username):
        
        User = get_user_model()
        try:
            user = User.objects.get(**{
                User.USERNAME_FIELD: username,
            })
            if user.is_active:
                raise ActivationError(
                    self.ALREADY_ACTIVATED_MESSAGE,
                    code='already_activated'
                )
            return user
        except User.DoesNotExist:
            raise ActivationError(
                self.BAD_USERNAME_MESSAGE,
                code='bad_username'
            )
627626
def set_account_username(account, old_username, new_username):
    
    for datastore in _get_datastores():
        datastore.set_account_username(account, old_username, new_username)
802031
def username(self, value):
        """"""
        if isinstance(value, str):
            self._username = value
            self._handler = None
1032329
def set_account_username(self, account, old_username, new_username):
        
        luser = self._get_account(old_username)
        rename(luser, database=self._database, uid=new_username)
590761
def user_exists(self, username):
        

        response = self._get(self.rest_url + "/user",
                             params={"username": username})

        if not response.ok:
            return None

        return True
970769
def validate_username(form, field):
        """"""
        try:
            validate_username(field.data)
        except ValueError as e:
            raise ValidationError(e)

        try:
            user_profile = UserProfile.get_by_username(field.data)
            if current_userprofile.is_anonymous or \
                    (current_userprofile.user_id != user_profile.user_id and
                     field.data != current_userprofile.username):
                # NOTE: Form validation error.
                raise ValidationError(_('Username already exists.'))
        except NoResultFound:
            return
1302240
def user(self, user):
        
        if user is None:
            raise ValueError("Invalid value for `user`, must not be `None`")
        if user is not None and len(user) > 1024:
            raise ValueError("Invalid value for `user`, length must be less than or equal to `1024`")

        self._user = user
178653
def unique_username_validator(form, field):
    
    user_manager =  current_app.user_manager
    if not user_manager.db_manager.username_is_available(field.data):
        raise ValidationError(_('This Username is already in use. Please try another one.'))
780531
def validate_username(username):
        
        try:
            validate_slug(username)
        except ValidationError:
            username = slugify(username)

        user_model_cls = get_user_model()
        _username = username
        while user_model_cls.objects.filter(username=_username).exists():
            _username = '{}{}'.format(username, random.randint(1, 100))

        return _username
1087710
def user=(new_user)
      if new_user && !new_user.respond_to?(:to_str)
        raise TypeError, "Can't convert #{new_user.class} into String."
      end
      @user = new_user ? new_user.to_str : nil

      # You can't have a nil user with a non-nil password
      if password != nil
        @user = EMPTY_STR if @user.nil?
      end

      # Reset dependent values
      remove_instance_variable(:@userinfo) if defined?(@userinfo)
      remove_instance_variable(:@normalized_userinfo) if defined?(@normalized_userinfo)
      remove_instance_variable(:@authority) if defined?(@authority)
      remove_instance_variable(:@normalized_user) if defined?(@normalized_user)
      remove_composite_values

      # Ensure we haven't created an invalid URI
      validate()
    end
288920
def change_name(self, username):
        
        self.release_name()

        try:
            self.server.register_name(username)
        except UsernameInUseException:
            logging.log(', '.join(self.server.registered_names))
            self.server.register_name(self.name)
            raise
            
        self.name = username
396493
def put(self, user_name: str) -> User:
        
        current = current_user()
        if current.name == user_name or current.is_admin:
            user = self._get_or_abort(user_name)
            self.update(user)
            session.commit()
            session.add(user)
            return user
        else:
            abort(403)
1361725
def validate_new_email(email):
    """"""
    email = normalize_email(email)
    User = get_user_model()  # noqa
    if User.objects.filter(email=email).exists():
        raise ValidationError('The given email address is already registered.')
1267470
def clean(self):
        
        if self.user:
            self.username = self.user.username
        elif not self.username:
            raise ValidationError({
                'username': _NOT_BLANK_MESSAGE,
                'user': _NOT_BLANK_MESSAGE
            })