Beispiel #1
0
 def _finalize_with_domain(self, domain):
     if domain.is_locally_registrable:
         # TODO the following line raises Domain.DoesNotExist under unknown conditions
         PDNSChangeTracker.track(lambda: DomainViewSet.auto_delegate(domain))
         token = models.Token.objects.create(user=domain.owner, name='dyndns')
         return Response({
             'detail': 'Success! Here is the password ("token") to configure your router (or any other dynDNS '
                       'client). This password is different from your account password for security reasons.',
             'domain': serializers.DomainSerializer(domain).data,
             **serializers.TokenSerializer(token, include_plain=True).data,
         })
     else:
         return Response({
             'detail': 'Success! Please check the docs for the next steps, https://desec.readthedocs.io/.',
             'domain': serializers.DomainSerializer(domain, include_keys=True).data,
         })
Beispiel #2
0
 def _create_domain(self):
     serializer = serializers.DomainSerializer(
         data={'name': self.action.domain},
         context=self.get_serializer_context())
     try:
         serializer.is_valid(raise_exception=True)
     except ValidationError as e:  # e.g. domain name unavailable
         self.action.user.delete()
         reasons = ', '.join(
             [detail.code for detail in e.detail.get('name', [])])
         raise ValidationError(
             f'The requested domain {self.action.domain} could not be registered (reason: {reasons}). '
             f'Please start over and sign up again.')
     # TODO the following line is subject to race condition and can fail, as for the domain name, we have that
     #  time-of-check != time-of-action
     return PDNSChangeTracker.track(
         lambda: serializer.save(owner=self.action.user))