def prepare_tester_registrant(tester=None, epp_id=None, profile_object=None, create_new=False): if not tester: tester = prepare_tester_account() tester_registrant = tester.registrants.first() if not tester_registrant or create_new: if profile_object: tester_registrant = zcontacts.registrant_create_from_profile( owner=tester, profile_object=profile_object, epp_id=epp_id, ) else: tester_registrant = zcontacts.registrant_create( epp_id=epp_id, owner=tester, person_name='Tester Registrant', organization_name='TestingCorp', address_street='TestStreet', address_city='TestCity', address_province='TestProvince', address_postal_code='TestPostalCode', address_country='AI', contact_voice='1234567890', contact_fax='1234567890', contact_email='*****@*****.**', ) return tester_registrant
def form_valid(self, form): existing_contacts = zcontacts.list_contacts(self.request.user) if not existing_contacts: new_contact = zcontacts.contact_create_from_profile( self.request.user, form.instance) if not zmaster.contact_create_update(new_contact): messages.error(self.request, self.error_message) return HttpResponseRedirect(self.request.path_info) existing_registrant = zcontacts.get_registrant(self.request.user) if not existing_registrant: new_registrant = zcontacts.registrant_create_from_profile( self.request.user, form.instance) if not zmaster.contact_create_update(new_registrant): messages.error(self.request, self.error_message) return HttpResponseRedirect(self.request.path_info) else: zcontacts.registrant_update_from_profile(existing_registrant, form.instance) if not zmaster.contact_create_update(existing_registrant): messages.error(self.request, self.error_message) return HttpResponseRedirect(self.request.path_info) if existing_registrant and existing_contacts: messages.success( self.request, 'Your profile information was successfully updated') else: messages.success( self.request, 'Profile information successfully updated, you can register new domains now' ) return super().form_valid(form)
def doDBCheckCreateUserAccount(self, *args, **kwargs): """ Action method. """ if self.known_registrant: logger.info( 'registrant already known so skip creating user account') return known_owner = zusers.find_account( self.current_registrant_info['email']) if not known_owner: known_owner = zusers.create_account( email=self.current_registrant_info['email'], account_password=zusers.generate_password(length=10), also_profile=True, is_active=True, person_name=self.current_registrant_address_info.get( 'name', 'unknown'), organization_name=self.current_registrant_address_info.get( 'org', 'unknown'), address_street=self.current_registrant_address_info.get( 'street', 'unknown'), address_city=self.current_registrant_address_info.get( 'city', 'unknown'), address_province=self.current_registrant_address_info.get( 'sp', 'unknown'), address_postal_code=self.current_registrant_address_info.get( 'pc', 'unknown'), address_country=self.current_registrant_address_info.get( 'cc', 'AF'), contact_voice=zcontacts.extract_phone_number( self.current_registrant_info.get('voice', '')), contact_fax=zcontacts.extract_phone_number( self.current_registrant_info.get('fax', '')), contact_email=self.current_registrant_info['email'], ) if not hasattr(known_owner, 'profile'): zusers.create_profile( known_owner, person_name=self.current_registrant_address_info.get( 'name', 'unknown'), organization_name=self.current_registrant_address_info.get( 'org', 'unknown'), address_street=self.current_registrant_address_info.get( 'street', 'unknown'), address_city=self.current_registrant_address_info.get( 'city', 'unknown'), address_province=self.current_registrant_address_info.get( 'sp', 'unknown'), address_postal_code=self.current_registrant_address_info.get( 'pc', 'unknown'), address_country=self.current_registrant_address_info.get( 'cc', 'AF'), contact_voice=zcontacts.extract_phone_number( self.current_registrant_info.get('voice', '')), contact_fax=zcontacts.extract_phone_number( self.current_registrant_info.get('fax', '')), contact_email=self.current_registrant_info['email'], ) self.received_registrant_epp_id = self.new_registrant_epp_id self.known_registrant = zcontacts.registrant_find( epp_id=self.received_registrant_epp_id) if not self.known_registrant: logger.info('new registrant will be created for %r', known_owner) self.known_registrant = zcontacts.registrant_create_from_profile( owner=known_owner, profile_object=known_owner.profile, epp_id=self.received_registrant_epp_id, ) if self.target_domain: zdomains.domain_detach_contact(self.target_domain, 'admin') zdomains.domain_detach_contact(self.target_domain, 'billing') zdomains.domain_detach_contact(self.target_domain, 'tech') self.new_domain_contacts.pop('admin', None) self.new_domain_contacts.pop('billing', None) self.new_domain_contacts.pop('tech', None) if self.target_domain: self.target_domain.refresh_from_db()