Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Verifies whether a given CalLink OID is eligible for a new OCF account.
Checks that:
- User doesn't already have an OCF account
Issues a warning which staff can override if they do (unlike
validate_calnet_uid, which issues an error).
OID `0` can create an infinite number of accounts; we use this for
department-sponsored groups and others without CalLink OIDs.
"""
if oid == 0:
return
# check for existing OCF accounts
existing_accounts = search.users_by_callink_oid(oid)
if existing_accounts:
raise ValidationWarning(
'CalLink OID already has account: ' + str(existing_accounts))
def get_calnet_names(uid):
"""Returns CalNet LDAP entries relating to names"""
attrs = search.user_attrs_ucb(uid)
if attrs:
return {key: attrs[key]
for key in ('givenName', 'sn', 'displayName') if key in attrs}
def validate_username(username, realname):
"""Validates a username and realname pair to ensure:
* Username isn't already in use
* Username is based on realname
* Username isn't restricted."""
if search.user_exists(username):
raise ValidationError('Username {} already exists.'.format(username))
try:
validators.validate_username(username)
except ValueError as ex:
raise ValidationError(str(ex))
SIMILARITY_THRESHOLD = 2
if similarity_heuristic(realname, username) > SIMILARITY_THRESHOLD:
raise ValidationWarning(
'Username {} not based on real name {}.'.format(username, realname))
if any(word in username for word in BAD_WORDS):
raise ValidationWarning('Username {} contains bad words.'.format(username))