Exemple #1
0
 def clean_your_email(self) -> str:
     your_email = self.cleaned_data['your_email']
     if not valid_email(your_email):
         raise forms.ValidationError(
             "The email you entered doesn't appear to be "
             'valid. Please double-check it.', )
     return your_email
Exemple #2
0
 def clean_your_email(self):
     your_email = self.cleaned_data['your_email']
     if not valid_email(your_email):
         raise forms.ValidationError(
             "The email you entered doesn't appear to be "
             'valid. Please double-check it.'
         )
     return your_email
Exemple #3
0
def send_mail(to, subject, body, sender=MAIL_FROM):
    """Send a plain-text mail message.

    `body` should be a string with newlines, wrapped at about 80 characters."""

    if not validators.valid_email(parseaddr(sender)[1]):
        raise ValueError('Invalid sender address.')

    if not validators.valid_email(parseaddr(to)[1]):
        raise ValueError('Invalid recipient address.')

    msg = email.mime.text.MIMEText(body)

    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = to

    # we send the message via sendmail, since we may one day prohibit traffic
    # to port 25 that doesn't go via the system mailserver
    p = subprocess.Popen((SENDMAIL_PATH, '-t', '-oi'), stdin=subprocess.PIPE)
    p.communicate(msg.as_string().encode('utf8'))
Exemple #4
0
def send_mail(to, subject, body, sender=constants.MAIL_FROM):
    """Send a plain-text mail message.

    `body` should be a string with newlines, wrapped at about 80 characters."""

    if not validators.valid_email(parseaddr(sender)[1]):
        raise ValueError('Invalid sender address.')

    if not validators.valid_email(parseaddr(to)[1]):
        raise ValueError('Invalid recipient address.')

    msg = email.mime.text.MIMEText(body)

    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = to

    # we send the message via sendmail, since we may one day prohibit traffic
    # to port 25 that doesn't go via the system mailserver
    p = subprocess.Popen((constants.SENDMAIL_PATH, '-t', '-oi'),
                         stdin=subprocess.PIPE)
    p.communicate(msg.as_string().encode('utf8'))
Exemple #5
0
def send_mail(to, subject, body, *, cc=None, sender=MAIL_FROM):
    """Send a plain-text mail message.

    `body` should be a string with newlines, wrapped at about 80 characters."""

    if not validators.valid_email(parseaddr(sender)[1]):
        raise ValueError('Invalid sender address.')

    if not validators.valid_email(parseaddr(to)[1]):
        raise ValueError('Invalid recipient address.')

    msg = email.mime.text.MIMEText(body)

    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = to
    msg['Cc'] = cc

    # we send the message via sendmail because direct traffic to port 25
    # is firewalled off
    p = subprocess.Popen((SENDMAIL_PATH, '-t', '-oi'), stdin=subprocess.PIPE)
    p.communicate(msg.as_string().encode('utf8'))
Exemple #6
0
def validate_email(email):
    if not valid_email(email):
        raise ValidationError('Invalid email.')
Exemple #7
0
def validate_email(email):
    if not valid_email(email):
        raise ValidationError('Invalid email.')
Exemple #8
0
def request_vhost(request):
    user = request.session['ocf_user']
    attrs = search.user_attrs(user)
    error = None

    if account.has_vhost(user):
        return render_to_response(
            'already_have_vhost.html', {'user': user})

    if request.method == 'POST':
        form = VirtualHostForm(request.POST)

        if form.is_valid():
            requested_subdomain = form.cleaned_data['requested_subdomain']
            requested_why = form.cleaned_data['requested_why']
            comments = form.cleaned_data['comments']
            your_name = form.cleaned_data['your_name']
            your_email = form.cleaned_data['your_email']
            your_position = form.cleaned_data['your_position']

            full_domain = '{}.berkeley.edu'.format(requested_subdomain)

            # verify that the requested domain is available
            if validators.host_exists(full_domain):
                error = 'The domain you requested is not available. ' + \
                    'Please select a different one.'

            if not validators.valid_email(your_email):
                error = "The email you entered doesn't appear to be " + \
                    'valid. Please double-check it.'

            if not error:
                # send email to hostmaster@ocf and redirect to success page
                ip_addr = get_client_ip(request)

                try:
                    ip_reverse = socket.gethostbyaddr(ip_addr)[0]
                except:
                    ip_reverse = 'unknown'

                subject = 'Virtual Hosting Request: {} ({})'.format(
                    full_domain, user)
                message = (
                    'Virtual Hosting Request:\n' +
                    '  - OCF Account: {user}\n' +
                    '  - OCF Account Title: {title}\n' +
                    '  - Requested Subdomain: {full_domain}\n' +
                    '  - Current URL: https://ocf.io/{user}/\n' +
                    '\n' +
                    'Request Reason:\n' +
                    '{requested_why}\n\n' +
                    'Comments/Special Requests:\n' +
                    '{comments}\n\n' +
                    'Requested by:\n' +
                    '  - Name: {your_name}\n' +
                    '  - Position: {your_position}\n' +
                    '  - Email: {your_email}\n' +
                    '  - IP Address: {ip_addr} ({ip_reverse})\n' +
                    '  - User Agent: {user_agent}\n' +
                    '\n\n' +
                    '--------\n' +
                    'Request submitted to atool ({hostname}) on {now}.\n' +
                    '{full_path}').format(
                        user=user,
                        title=attrs['cn'][0],
                        full_domain=full_domain,
                        requested_why=requested_why,
                        comments=comments,
                        your_name=your_name,
                        your_position=your_position,
                        your_email=your_email,
                        ip_addr=ip_addr,
                        ip_reverse=ip_reverse,
                        user_agent=request.META.get('HTTP_USER_AGENT'),
                        now=datetime.datetime.now().strftime(
                            '%A %B %e, %Y @ %I:%M:%S %p'),
                        hostname=socket.gethostname(),
                        full_path=request.build_absolute_uri())

                from_addr = email.utils.formataddr((your_name, your_email))
                to = ('*****@*****.**',)

                try:
                    send_mail(subject, message, from_addr, to,
                              fail_silently=False)
                    return redirect(reverse('request_vhost_success'))
                except Exception as ex:
                    print(ex)
                    print('Failed to send vhost request email!')
                    error = \
                        'We were unable to submit your virtual hosting ' + \
                        'request. Please try again or email us at ' + \
                        '*****@*****.**'
    else:
        form = VirtualHostForm(initial={'requested_subdomain': user})

    group_url = 'http://www.ocf.berkeley.edu/~{0}/'.format(user)

    return render_to_response('request_vhost.html', {
        'form': form,
        'user': user,
        'attrs': attrs,
        'group_url': group_url,
        'error': error
    }, context_instance=RequestContext(request))
Exemple #9
0
def test_valid_email(email, valid):
    assert valid_email(email) == valid
Exemple #10
0
def test_valid_email(email, valid):
    assert valid_email(email) == valid