<commit_before>from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.views.decorators.debug import sensitive_variables
from accounts.models import CuLdapUser
from accounts.models import CsuLdapUser
from accounts.models import RcLdapUser
from accounts.models import AccountRequest
from accounts.models import SHELL_CHOICES
from accounts.models import REQUEST_ROLES
from projects.models import Project



class AccountRequestForm(forms.Form):
    ORGS = (
        ('ucb','University of Colorado Boulder'),
        ('csu','Colorado State University'),
        # ('xsede','XSEDE'),
    )
    organization = forms.ChoiceField(choices=ORGS,required=True)
    username = forms.CharField(max_length=12,required=True)
    password = forms.CharField(max_length=255,widget=forms.PasswordInput)

    role = forms.ChoiceField(choices=REQUEST_ROLES)
    login_shell = forms.ChoiceField(required=False,choices=SHELL_CHOICES)

    blanca = forms.BooleanField(required=False)
    janus = forms.BooleanField(required=False)
    summit = forms.BooleanField(required=False)
    petalibrary_active = forms.BooleanField(required=False)
    petalibrary_archive = forms.BooleanField(required=False)

    @sensitive_variables('pw')
    def clean(self):
        cleaned_data = super(AccountRequestForm,self).clean()
        un = cleaned_data.get('username')
        pw = cleaned_data.get('password')
        org = cleaned_data.get('organization')
        ars = AccountRequest.objects.filter(username=un)
        for ar in ars:
            if org == ar.organization:
                raise forms.ValidationError(
                    'An account request has already been submitted for {}'.format(un)
                )
        try:
            rcu = RcLdapUser.objects.filter(username=un)
            for u in rcu:
                if org == u.organization:
                    raise forms.ValidationError(
                        'An account already exists with username {}'.format(un)
                    )
            authed = False
            if org == 'ucb':
                user = CuLdapUser.objects.get(username=un)
                authed = user.authenticate(pw)
            elif org == 'csu':
                user = CsuLdapUser.objects.get(username=un)
                authed = user.authenticate(pw)
            elif org == 'xsede':
                pass
            if not authed:
                raise forms.ValidationError('Invalid password')
            return cleaned_data<commit_msg>Fixed org matching in account request form. #174<commit_after>from django import forms
from django.contrib.admin.widgets import FilteredSelectMultiple
from django.views.decorators.debug import sensitive_variables
from accounts.models import CuLdapUser
from accounts.models import CsuLdapUser
from accounts.models import RcLdapUser
from accounts.models import AccountRequest
from accounts.models import SHELL_CHOICES
from accounts.models import REQUEST_ROLES
from projects.models import Project



class AccountRequestForm(forms.Form):
    ORGS = (
        ('ucb','University of Colorado Boulder'),
        ('csu','Colorado State University'),
        # ('xsede','XSEDE'),
    )
    organization = forms.ChoiceField(choices=ORGS,required=True)
    username = forms.CharField(max_length=12,required=True)
    password = forms.CharField(max_length=255,widget=forms.PasswordInput)

    role = forms.ChoiceField(choices=REQUEST_ROLES)
    login_shell = forms.ChoiceField(required=False,choices=SHELL_CHOICES)

    blanca = forms.BooleanField(required=False)
    janus = forms.BooleanField(required=False)
    summit = forms.BooleanField(required=False)
    petalibrary_active = forms.BooleanField(required=False)
    petalibrary_archive = forms.BooleanField(required=False)

    @sensitive_variables('pw')
    def clean(self):
        cleaned_data = super(AccountRequestForm,self).clean()
        un = cleaned_data.get('username')
        pw = cleaned_data.get('password')
        org = cleaned_data.get('organization')
        ars = AccountRequest.objects.filter(username=un)
        for ar in ars:
            if org == ar.organization:
                raise forms.ValidationError(
                    'An account request has already been submitted for {}'.format(un)
                )
        try:
            rcu = RcLdapUser.objects.filter(username=un)
            for u in rcu:
                user_org = u.org.split('=')[-1]
                if org == user_org.lower():
                    raise forms.ValidationError(
                        'An account already exists with username {}'.format(un)
                    )
            authed = False
            if org == 'ucb':
                user = CuLdapUser.objects.get(username=un)
                authed = user.authenticate(pw)
            elif org == 'csu':
                user = CsuLdapUser.objects.get(username=un)
                authed = user.authenticate(pw)
            elif org == 'xsede':
                pass
            if not authed:
                raise forms.ValidationError('Invalid password')
            return cleaned_data
{'fraction_non_alphanumeric': 0.09098023870084132, 'fraction_numerical': 0.0027391899823909216, 'mean_word_length': 2.5524669909659488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3675591', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1354, 'n_words': 306}