Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_calnet_uid(uid):
"""Verifies whether a given CalNet UID is eligible for a new OCF account.
Checks that:
- User doesn't already have an OCF account
- Affiliate type is eligible"""
# check for existing OCF accounts
existing_accounts = search.users_by_calnet_uid(uid)
if existing_accounts:
raise ValidationError(
'CalNet UID already has account: ' + str(existing_accounts))
attrs = search.user_attrs_ucb(uid)
if not attrs:
raise ValidationError("CalNet UID can't be found in university LDAP.")
def parse(student):
uid = int(student.findtext('Username'))
name = name_by_calnet_uid(uid)
users = search.users_by_calnet_uid(uid)
return uid, {'name': name, 'accounts': users}
def request_account(request: HttpRequest) -> Union[HttpResponseRedirect, HttpResponse]:
calnet_uid = request.session['calnet_uid']
status = 'new_request'
existing_accounts = search.users_by_calnet_uid(calnet_uid)
if existing_accounts and calnet_uid not in TESTER_CALNET_UIDS:
return render(
request,
'account/register/already-has-account.html',
{
'account': ', '.join(existing_accounts),
'calnet_uid': calnet_uid,
'title': 'You already have an account',
},
)
# ensure we can even find them in university LDAP
# (alumni etc. might not be readable in LDAP but can still auth via CalNet)
if not user_attrs_ucb(calnet_uid):
return render(
def request_account(request):
calnet_uid = request.session['calnet_uid']
existing_accounts = search.users_by_calnet_uid(calnet_uid)
real_name = directory.name_by_calnet_uid(calnet_uid)
if calnet_uid not in settings.TESTER_CALNET_UIDS and existing_accounts:
return render_to_response('already_requested_account.html', {
'calnet_uid': calnet_uid,
'calnet_url': settings.LOGOUT_URL
})
if request.method == 'POST':
form = ApproveForm(request.POST)
if form.is_valid():
account_name = form.cleaned_data['ocf_login_name']
email_address = form.cleaned_data['contact_email']
password = form.cleaned_data['password']
try:
def get_accounts_for(calnet_uid: str) -> List[Any]:
accounts = users_by_calnet_uid(calnet_uid)
if calnet_uid in TESTER_CALNET_UIDS:
# these test accounts don't have to exist in in LDAP
accounts.extend(TEST_OCF_ACCOUNTS)
return accounts