Ensures that mobile and email tokens are unique or tries once more to generate.
340856
def check_unique_tokens(sender, instance, **kwargs):
    
    if isinstance(instance, CallbackToken):
        if CallbackToken.objects.filter(key=instance.key, is_active=True).exists():
            instance.key = generate_numeric_token()
868161
public function isUniqueEmail($uEmail)
    {
        $app = Application::getFacadeApplication();

        return $app->make(UniqueUserEmailValidator::class)->isValid($uEmail);
    }
164425
def check_unique(self):
        """"""
        errors = []
        service_id = getattr(self, 'id', None)
        fields = [('location', views.service_location),
                  ('name', views.service_name)]

        for field, view in fields:
            value = getattr(self, field, None)
            if not value:
                continue

            result = yield view.values(key=value)
            matched = {x['id'] for x in result if x['id'] != service_id}
            if matched:
                errors.append("Service with {} '{}' already exists"
                              .format(field, value))

        if errors:
            raise exceptions.ValidationError(errors)
1188816
public function getUniqueToken()
    {
        $tries = 0;
        $candidate = $this->cretateToken();
        // give up and throw an exception if it seems impossible to create a unique token
        while ($tries++ < 5 && in_array($candidate, $this->generated)) {
            $candidate = $this->cretateToken();
        }
        if (in_array($candidate, $this->generated)) {
            throw new \RuntimeException("failed to create a new unique token");
        }

        $this->generated[] = $candidate;

        return $candidate;
    }
776967
function (uid, token_source, onDone) {
	
	// generate a valid token to be returned
	var token = UTIL.createToken();
	
	// store token back to DB
	var onUpdated = function (error) {
		if (error) {
			var err = new Error(error.toString());
			err.name = "l_createToken Error";
			UTIL.safeCall(onDone, err);
		}
		else {
			LOG.warn('pass_token [' + token + '] stored');
			UTIL.safeCall(onDone, null, token);			
		}
	};
	l_updateUser({uid: uid}, 'pass_tokens.' + token, token_source, onUpdated);
}
856719
def unique_email_validator(form, field):
    
    user_manager =  current_app.user_manager
    if not user_manager.email_is_available(field.data):
        raise ValidationError(_('This Email is already in use. Please try another one.'))
1160232
function initializeUnique() {
  uniquecoll = db.addCollection('uniquecoll', {
    unique: ['customId']
  });

  for (var idx = 0; idx < arraySize; idx++) {
    var v1 = genRandomVal();
    var v2 = genRandomVal();

    uniquecoll.insert({
      customId: (arraySize - idx),
      val: v1,
      val2: v2,
      val3: "more data 1234567890"
    });
  }
}
734625
def validate_unique(self, exclude=None):
        
        # This is called from ModelForm._post_clean() or Model.full_clean()
        errors = {}
        try:
            super(TranslatableModelMixin, self).validate_unique(exclude=exclude)
        except ValidationError as e:
            errors = e.message_dict

        for local_cache in six.itervalues(self._translations_cache):
            for translation in six.itervalues(local_cache):
                if is_missing(translation):  # Skip fallback markers
                    continue

                try:
                    translation.validate_unique(exclude=exclude)
                except ValidationError as e:
                    errors.update(e.message_dict)

        if errors:
            raise ValidationError(errors)
1257072
def ensureHashIndex(self, fields, unique = False, sparse = True, deduplicate = False) :
        """"""
        data = {
            "type" : "hash",
            "fields" : fields,
            "unique" : unique,
            "sparse" : sparse,
            "deduplicate": deduplicate
        }
        ind = Index(self, creationData = data)
        self.indexes["hash"][ind.infos["id"]] = ind
        return ind
803429
function unique (elements) {
  for (var i = 0; i < elements.length - 1; i++) {
    for (var j = i + 1; j < elements.length; j++) {
      if (elements[i] === elements[j]) return false
    }
  }

  return true
}
1115896
def create_password_reset(cls, email, valid_for=3600) -> str:
        
        user = cls.where_email(email)
        if user is None:
            return None
        PasswordResetModel.delete_where_user_id(user.id)
        token = JWT().create_token({
            'code': Security.random_string(5),  # make unique
            'user_id': user.id},
            token_valid_for=valid_for)
        code = Security.generate_uuid(1) + "-" + Security.random_string(5)
        password_reset_model = PasswordResetModel()
        password_reset_model.token = token
        password_reset_model.code = code
        password_reset_model.user_id = user.id
        password_reset_model.save()
        return code
57912
def validate_token(self, token):
    '''
    '''
    # A token that is finished or revoked is not valid
    subid = None
    if not token.endswith(('finished','revoked')):
        subid = self.generate_subid(token=token)
        data_base = "%s/%s" %(self.data_base, subid)
        if not os.path.exists(data_base):
            subid = None
    return subid
813935
def uniqify(func):
  """"""
  @six.wraps(func)
  def unique(self, *args, **kwargs):
    return self.unique(func(self, *args, **kwargs))
  return unique
991568
def validate(self):
        """"""
        try:
            # update _resource to have default values from the schema
            self._resource = self.schema(self._resource)
        except MultipleInvalid as e:
            errors = [format_error(err, self.resource_type) for err in e.errors]
            raise exceptions.ValidationError({'errors': errors})

        yield self.check_unique()
972522
def checkAndCreate(self, key, payload):
        
        if key not in self:
            if 'templates' in payload:
                templates = payload.pop('templates')
            self[key] = payload
            self.reload()
        return self[key]['id']
186597
def refresh_token(self, pattern=KEY_PATTERN):
        
        self.token = generate_token(pattern)
        self.save()
846659
def distinct(self, fieldname, key=None):
        
        return tuple(unique_everseen(self[fieldname], key=key))