示例#1
0
def submit_email(environ, start_response, data):
  email = data.get('email', '').strip()
  try:
    email = encode_email_address(email)
  except ValueError:
    return send_simple_response(
      start_response, 400,
      'Please enter a valid email address.'
    )

  config = get_config()
  params = [('email', email), ('signature', sign(config, email))]
  lang = data.get('lang')
  if lang:
    params.append(('lang', lang))

  sendMail(
    config.get('submit_email', 'verification_email_template'),
    {
      'recipient': email,
      'verification_url': '%s?%s' % (
        urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH),
        urlencode(params)
      )
    }
  )

  return send_simple_response(
    start_response, 200,
    'A confirmation email has been sent. Please check '
    'your email and click the confirmation link.'
  )
def send_installation_link(environ, start_response, data):
    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(start_response, 400,
                                    'Please enter a valid email address.')

    config = get_config()
    template_path = config.get('send_installation_link', 'email_template')
    sendMail(template_path, {'recipient': email})

    return send_simple_response(
        start_response, 200, 'The app is on the way! '
        'Please check your email on your smartphone or tablet.')
def send_installation_link(environ, start_response, data):
    email = data.get("email", "").strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(start_response, 400,
                                    "Please enter a valid email address.")

    config = get_config()
    template_path = config.get("send_installation_link", "email_template")
    sendMail(template_path, {"recipient": email})

    return send_simple_response(
        start_response, 200, "The app is on the way! "
        "Please check your email on your smartphone or tablet.")
示例#4
0
def validate_fields(fields, params):
    errors = []
    for field, spec in fields.items():
        if 'mandatory' in spec.value and field not in params:
            errors.append(
                make_error(spec, 'mandatory', 'No {} entered'.format(field)))
        if 'email' in spec.value and field in params:
            try:
                params[field] = encode_email_address(params[field])
            except ValueError:
                errors.append(make_error(spec, 'email', 'Invalid email'))

    unexpected_fields = ' '.join(set(params.keys()) - set(fields.keys()))
    if unexpected_fields:
        errors.append('Unexpected field/fields: ' + str(unexpected_fields))
    return errors
示例#5
0
def submit_email(environ, start_response, data):
    config = get_config()

    try:
        product = data['product']
        template = config.get('submit_email',
                              product + '_verification_email_template')
    except (KeyError, ConfigParser.NoOptionError):
        return send_simple_response(start_response, 400, 'Unknown product')

    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response,
            400,
            'Please enter a valid email address.',
        )

    params = [('email', email), ('signature', sign(config, email)),
              ('product', product)]
    lang = data.get('lang')
    if lang:
        params.append(('lang', lang))

    sendMail(
        template,
        {
            'recipient':
            email,
            'verification_url':
            '%s?%s' % (
                urljoin(wsgiref.util.application_uri(environ),
                        VERIFICATION_PATH),
                urlencode(params),
            ),
        },
    )

    return send_simple_response(
        start_response,
        200,
        'A confirmation email has been sent. Please check '
        'your email and click the confirmation link.',
    )
def send_installation_link(environ, start_response, data):
    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response, 400,
            'Please enter a valid email address.',
        )

    config = get_config()
    template_path = config.get('send_installation_link', 'email_template')
    sendMail(template_path, {'recipient': email})

    return send_simple_response(
        start_response, 200,
        'The app is on the way! '
        'Please check your email on your smartphone or tablet.',
    )
示例#7
0
def submit_email(environ, start_response, data):
    config = get_config()

    try:
        product = data['product']
        template = config.get('submit_email', product + '_verification_email_template')
    except (KeyError, ConfigParser.NoOptionError):
        return send_simple_response(start_response, 400, 'Unknown product')

    email = data.get('email', '').strip()
    try:
        email = encode_email_address(email)
    except ValueError:
        return send_simple_response(
            start_response, 400,
            'Please enter a valid email address.',
        )

    params = [('email', email), ('signature', sign(config, email)), ('product', product)]
    lang = data.get('lang')
    if lang:
        params.append(('lang', lang))

    sendMail(
        template,
        {
            'recipient': email,
            'verification_url': '%s?%s' % (
                urljoin(wsgiref.util.application_uri(environ), VERIFICATION_PATH),
                urlencode(params),
            ),
        },
    )

    return send_simple_response(
        start_response, 200,
        'A confirmation email has been sent. Please check '
        'your email and click the confirmation link.',
    )
示例#8
0
    def handler(environ, start_response, params):
        response_headers = [('Content-Type', 'text/plain; charset=utf-8')]
        errors = []
        for field, spec in fields.items():
            if 'mandatory' in spec.value:
                if field not in params.keys():
                    errors.append(make_error(spec, 'mandatory',
                                             'No {} entered'.format(field)))
            if 'email' in spec.value and field in params.keys():
                try:
                    params[field] = encode_email_address(params[field])
                except ValueError:
                    errors.append(make_error(spec, 'email', 'Invalid email'))
        if errors:
            start_response('400 Bad Request', response_headers)
            return '\n'.join(errors)

        template_args = {
            'time': datetime.datetime.now(),
            'fields': {field: params.get(field, '') for field in fields}
        }
        sendMail(template, template_args)
        start_response('200 OK', response_headers)
        return ''