Exemplo n.º 1
0
def domain_verify(request, domain_id):
    domain = get_object_or_404(Domain, id=domain_id, owner=request.user)
    valid = False
    if request.method == 'POST':
        if u'http' in request.POST:
            if (http_validate_ownership(domain.validation_url) or
                http_validate_ownership(domain.validation_url_with_www_prefix)):
                valid = True
        elif u'dns' in request.POST:
            if dns_validate_ownership(domain.name, domain.validation_key):
                valid = True
        else:
            raise ValueError("No validation mode in POST request, "
                             "it must have either 'http' or 'dns'.")

        if valid:
            domain.validated = True
            domain.save()
            messages.success(
                request, _(u'The domain ownership was successfully verified'))
            return HttpResponseRedirect(reverse('account_profile'))
        else:
            messages.error(
                request, _(u'Error while checking domain ownership'))

    return render_to_response('domain/verify.html', {
            'domain': domain,
            }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def domain_verify(request, domain_id, token=False):
    domain = get_object_or_404(Domain, id=domain_id, owner=request.user)
    valid = False
    check = False
    if request.method == 'POST':
        check = True
        if u'http' in request.POST:
            valid = (http_validate_ownership(domain.validation_url, domain.validation_key) or
                     http_validate_ownership(domain.validation_url_with_www_prefix, domain.validation_key))
            if not valid:
                messages.error(
                    request, _(u'Error HTTP validation: Unreachable URL or the validation-code was not found'))
        elif u'https' in request.POST:
            valid = (http_validate_ownership(domain.validation_secure_url, domain.validation_key) or
                     http_validate_ownership(domain.validation_secure_url_with_www_prefix, domain.validation_key))
            if not valid:
                messages.error(
                    request, _(u'Error HTTPs validation: Unreachable URL or the validation-code was not found'))
        elif u'dns' in request.POST:
            valid = dns_validate_ownership(domain.name, domain.validation_key, request=request)
            if not valid:
                messages.info(
                    request, _(u'Do not try again until the zone has been propagated and the DNS cached cleaned'))
        elif u'email' in request.POST:
            check = False
            token = uuid.uuid4().hex
            DomainToken.objects.create(domain=domain.name, token=token)
            send_mail_for_validation(request, domain, token, request.POST.get('mail'))
            messages.success(
                request, _(u'An email has been sent to %(domain_email)s') % {'domain_email': request.POST.get('mail')})
        else:
            raise ValueError("No validation mode selected'.")

    if request.method == 'GET' and token:
        check = True
        valid = email_validate_ownership(domain.name, token)
        if not valid:
            messages.warning(
                request, _(u'Error Email validation: Invalid token provided'))

    if check:
        if valid:
            return _domain_validate(request, domain)
        else:
            messages.error(
                request, _(u'Error while checking domain ownership'))

    domain_contact_list = get_administrative_emails_from_whois(domain.name)

    whois_has_emails = False
    if domain_contact_list:
        whois_has_emails = True

    domain_contact_list += get_administrative_emails_from_settings(domain.name)
    domain_contact_list = list(set(domain_contact_list))

    return render_to_response('domain/verify.html', {
        'domain': domain,
        'domain_contact_list': domain_contact_list,
        'whois_has_emails': whois_has_emails,
    }, context_instance=RequestContext(request))
Exemplo n.º 3
0
def domain_verify(request, domain_id, token=False):
    domain = get_object_or_404(Domain, id=domain_id, owner=request.user)
    valid = False
    check = False
    if request.method == 'POST':
        check = True
        if u'http' in request.POST:
            valid = (http_validate_ownership(domain.validation_url, domain.validation_key) or
                     http_validate_ownership(domain.validation_url_with_www_prefix, domain.validation_key))
            if not valid:
                messages.error(
                    request, _(u'Error HTTP validation: Unreachable URL or the validation-code was not found'))
        elif u'https' in request.POST:
            valid = (http_validate_ownership(domain.validation_secure_url, domain.validation_key) or
                     http_validate_ownership(domain.validation_secure_url_with_www_prefix, domain.validation_key))
            if not valid:
                messages.error(
                    request, _(u'Error HTTPs validation: Unreachable URL or the validation-code was not found'))
        elif u'dns' in request.POST:
            valid = dns_validate_ownership(domain.name, domain.validation_key, request=request)
            if not valid:
                messages.info(
                    request, _(u'Do not try again until the zone has been propagated and the DNS cached cleaned'))
        elif u'email' in request.POST:
            check = False
            token = uuid.uuid4().hex
            DomainToken.objects.create(domain=domain.name, token=token)
            send_mail_for_validation(request, domain, token, request.POST.get('mail'))
            messages.success(
                request, _(u'An email has been sent to %(domain_email)s') % {'domain_email': request.POST.get('mail')})
        else:
            raise ValueError("No validation mode selected'.")

    if request.method == 'GET' and token:
        check = True
        valid = email_validate_ownership(domain.name, token)
        if not valid:
            messages.warning(
                request, _(u'Error Email validation: Invalid token provided'))

    if check:
        if valid:
            return _domain_validate(request, domain)
        else:
            messages.error(
                request, _(u'Error while checking domain ownership'))

    domain_contact_list = get_administrative_emails_from_whois(domain.name)

    whois_has_emails = False
    if domain_contact_list:
        whois_has_emails = True

    domain_contact_list += get_administrative_emails_from_settings(domain.name)
    domain_contact_list = list(set(domain_contact_list))

    return render_to_response('domain/verify.html', {
        'domain': domain,
        'domain_contact_list': domain_contact_list,
        'whois_has_emails': whois_has_emails,
    }, context_instance=RequestContext(request))