示例#1
0
    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)
示例#2
0
 def doDBCheckCreateUpdateContacts(self, *args, **kwargs):
     """
     Action method.
     """
     if self.rewrite_contacts:
         # that indicates that we actually want to overwrite domain contacts on back-end
         if self.target_domain:
             # when domain exists - skip
             return
         first_contact = self.known_registrant.owner.contacts.first()
         if not first_contact:
             first_contact = zcontacts.contact_create_from_profile(
                 self.known_registrant.owner,
                 self.known_registrant.owner.profile)
         # only populate Admin contact from one of the existing contacts that must already exist!
         self.new_domain_contacts = {
             'admin': first_contact.epp_id,
         }
         return
     received_contacts_info = args[0]
     # even if domain not exist yet make sure all contacts really exists in DB and in sync with back-end
     for role in [
             'admin',
             'billing',
             'tech',
     ]:
         received_contact_id = received_contacts_info.get(
             role, {
                 'id': None,
             })['id']
         if not received_contact_id:
             continue
         existing_contact = zcontacts.by_epp_id(epp_id=received_contact_id)
         if existing_contact:
             if existing_contact.owner != self.known_registrant.owner:
                 if self.change_owner_allowed:
                     continue
                 logger.error(
                     'existing contact have another owner in local DB')
                 self.event(
                     'error',
                     zerrors.RegistrantAuthFailed(
                         'existing contact have another owner in local DB'))
                 return
             zcontacts.contact_refresh(
                 epp_id=received_contact_id,
                 contact_info_response=received_contacts_info[role]
                 ['response'],
             )
         else:
             zcontacts.contact_create(
                 epp_id=received_contact_id,
                 owner=self.known_registrant.owner,
                 contact_info_response=received_contacts_info[role]
                 ['response'],
             )
示例#3
0
 def doDBSetDomainContacts(self, *args, **kwargs):
     """
     Action method.
     """
     first_contact = self.known_registrant.owner.contacts.first()
     if not first_contact:
         first_contact = zcontacts.contact_create_from_profile(
             self.known_registrant.owner,
             self.known_registrant.owner.profile)
     zdomains.domain_join_contact(self.target_domain, 'admin',
                                  first_contact)
     self.target_domain.refresh_from_db()
示例#4
0
 def doUseExistingContacts(self, *args, **kwargs):
     """
     Action method.
     """
     self.new_registrant_epp_id = self.known_registrant.epp_id
     first_contact = self.known_registrant.owner.contacts.first()
     if not first_contact:
         first_contact = zcontacts.contact_create_from_profile(
             self.known_registrant.owner,
             self.known_registrant.owner.profile)
     if first_contact.epp_id:
         if not self.new_domain_contacts.get('admin'):
             self.new_domain_contacts['admin'] = first_contact.epp_id
     if self.target_domain:
         self.target_domain.refresh_from_db()
         target_contacts = None
         if not self.target_domain.list_contacts():
             target_contacts = list({
                 'admin': first_contact,
                 'billing': first_contact,
                 'tech': first_contact,
             }.items()),
         self.contacts_to_add, self.contacts_to_remove, change_registrant = zdomains.compare_contacts(
             domain_object=self.target_domain,
             domain_info_response=self.domain_info_response,
             target_contacts=target_contacts,
         )
         if change_registrant and self.rewrite_contacts:
             self.new_registrant_epp_id = change_registrant
             self.received_contacts.clear()
             for role, cont in self.target_domain.list_contacts():
                 if cont and cont.epp_id:
                     self.received_contacts.append({
                         'type': role,
                         'id': cont.epp_id,
                     })
示例#5
0
def test_contact_create_from_profile():
    tester = testsupport.prepare_tester_account(email='*****@*****.**')
    tester_contact = zcontacts.contact_create_from_profile(
        owner=tester, profile_object=tester.profile)
    assert tester_contact.owner.email == '*****@*****.**'