def clean_mobile_worker_username(domain, username, name_too_long_message=None, name_reserved_message=None, name_exists_message=None): max_username_length = get_mobile_worker_max_username_length(domain) if len(username) > max_username_length: raise forms.ValidationError(name_too_long_message or _( 'Username %(username)s is too long. Must be under %(max_length)s characters.' ) % { 'username': username, 'max_length': max_username_length }) if username in UNALLOWED_MOBILE_WORKER_NAMES: raise forms.ValidationError( name_reserved_message or _('The username "%(username)s" is reserved for CommCare.') % {'username': username}) username = format_username(username, domain) validate_username(username) if CouchUser.username_exists(username): raise forms.ValidationError(name_exists_message or _('This Mobile Worker already exists.')) return username
def clean_mobile_worker_username( domain, username, name_too_long_message=None, name_reserved_message=None, name_exists_message=None ): max_username_length = get_mobile_worker_max_username_length(domain) if len(username) > max_username_length: raise forms.ValidationError( name_too_long_message or _("Username %(username)s is too long. Must be under %(max_length)s characters.") % {"username": username, "max_length": max_username_length} ) if username in UNALLOWED_MOBILE_WORKER_NAMES: raise forms.ValidationError( name_reserved_message or _('The username "%(username)s" is reserved for CommCare.') % {"username": username} ) username = format_username(username, domain) validate_username(username) if CouchUser.username_exists(username): raise forms.ValidationError(name_exists_message or _("This Mobile Worker already exists.")) return username
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)
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)