Beispiel #1
0
    def clean(self):


        if "received_application" in self.cleaned_data \
           and self.cleaned_data["received_application"]:

            # email required if received
            if not "email" in self.cleaned_data \
               or not self.cleaned_data["email"]:
                self.add_error('email',_('required_attribute') )                

            if not "ldap_user_name" in self.cleaned_data \
               or not self.cleaned_data["ldap_user_name"]:
                self.add_error('ldap_user_name',_('required_attribute') )                

            # email should not exist before if received request
            email = ''
            exists = False
            if "email" in self.cleaned_data and self.cleaned_data["email"]:
                email = self.cleaned_data['email']
                exists = Person.ldap_uid_by_email(email)
            if exists:
                logging.warning(_('the_mail_is_required') % {'email':email})
                logging.warning('The email should not exist before if received request.')
                #self.add_error('email', _('the_mail_is_required') % {'email':email}  )
            
        if "ldap_user_name" in self.cleaned_data and self.cleaned_data["ldap_user_name"] \
        and not self.cleaned_data["received_application"]:
            self.add_error('received_application',_('received_application_required') )

        if self.instance.pk and not self.cleaned_data["group_id"]:
            self.add_error('group_id',_('required_attribute_group') )
            raise ValidationError(_('required_attribute_group'))

        if len(self.cleaned_data['ldap_user_password']) < settings.MIN_LENGTH_LDAP_USER_PASSWORD:
            raise ValidationError(_('ldap_user_password_too_short'))

        if "ldap_user_name" in self.cleaned_data \
           and self.cleaned_data["ldap_user_name"]:
            existing_names_in_ldap = Person.ldap_uid_by_id( self.cleaned_data['document_number'],
                                                            self.cleaned_data['document_type'] )
            if existing_names_in_ldap and (self.cleaned_data["ldap_user_name"] not in existing_names_in_ldap):
                logging.info("User has already exists in Ldap with uid '%s'. it was not updated!" \
                             % ','.join(existing_names_in_ldap))
                self.add_error('document_number',
                               _("user_ID_ldap_already_exists") % {'uid':','.join(existing_names_in_ldap)})
Beispiel #2
0
def check_ldap(request):
    existing_name_in_ldap = None
    doc_type = None
    result = False
        
    if 'ldap_user_name' in request.POST and request.POST['ldap_user_name']:
        if Person.exists_in_ldap( request.POST['ldap_user_name'] ):
            existing_name_in_ldap = request.POST['ldap_user_name']

    if 'doc_type' in request.POST and request.POST['doc_type']:
        doc_type = DocumentType.objects.get(pk=request.POST['doc_type'])
        if 'doc_num'  in request.POST and request.POST['doc_num']:
            existing_name_in_ldap = Person.ldap_uid_by_id( request.POST['doc_num'],
                                                           doc_type.name.upper() )
            
    if existing_name_in_ldap:
        result = True

    topic_list = json.dumps({'exists': result, 'uid_in_ldap': existing_name_in_ldap})
    return HttpResponse(topic_list)