def validate_id(self, id): # we can't always trust the id argument, b/c the autogen'd # id will be passed in if the reg form id field is blank form = self.REQUEST.form if form.has_key('id') and not form['id']: return self.translate('Input is required but no input given.', default='You did not enter a login name.'), elif self.id and id != self.id: # we only validate if we're changing the id mbtool = getToolByName(self, 'membrane_tool') if mbtool.getUserAuthProvider(id) is not None or \ not ALLOWED_MEMBER_ID_PATTERN.match(id) or \ id == 'Anonymous User': msg = "The login name you selected is already " + \ "in use or is not valid. Please choose another." return self.translate(msg, default=msg)
def validate_id(self, id): """ Override the default id validation to disallow ids that vary from existing ids only by case. """ # we can't always trust the id argument, b/c the autogen'd # id will be passed in if the reg form id field is blank form = self.REQUEST.form if form.has_key('id') and not form['id']: return self.translate('Input is required but no input given.', default='You did not enter a login name.') old_id = self.getId() if old_id is None or id == old_id: # we only validate if we're changing the id return # check this first to avoid bad tokens getting into the membertool search # see http://trac.openplans.org/openplans/ticket/2713 if not ALLOWED_MEMBER_ID_PATTERN.match(id): msg = "The login name you selected is not valid. " + \ "Usernames must start with a letter and consist " + \ "only of letters, numbers, and underscores. Please " +\ "choose another." return self.translate(msg, default=msg) for prefix in PROHIBITED_MEMBER_PREFIXES: if id.lower().startswith(prefix): msg = ("The login name you selected is not valid " + "because it starts with %s. Please choose " + "another.") % prefix return self.translate(msg, default=msg) mbtool = getToolByName(self, 'membrane_tool') case_insensitive_matches = mbtool.unrestrictedSearchResults(getUserName=id) if not form.has_key("skip_case_insensitive_username_check"): if len(case_insensitive_matches) > 0: msg = "The login name you selected is already " + \ "in use. Please choose another." return self.translate(msg, default=msg) for match in case_insensitive_matches: if match.getId == id: msg = "The login name you selected is already " + \ "in use. Please choose another." return self.translate(msg, default=msg)