コード例 #1
0
ファイル: templates.py プロジェクト: martyanov/webshop
def render_header():
    return """
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>

    <head>
      <title>%(title)s</title>
      <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
      <link rel="stylesheet" type="text/css" href="static/style.css">
      <link rel="icon" type="image/x-icon" href="static/epoint.ico">
    </head>

    <body>

      <div id="header">
      </div>
    """ % {'title': _('WebShop Mailreceipt')}
コード例 #2
0
    def index(self, email=None, pgp=None, mime=None, sn=None, **params):
        cherrypy.response.headers["Content-Type"] = "text/html"
        page = [render_header()]
        if cherrypy.request.method == "POST":
            # TODO: check email for validity
            if email is None or email == "":
                return self._render_error_page(_("Missing parameter"), _("Email parameter is mandatory."))
            # TODO: check serial number for validity
            if sn is None or sn == "":
                return self._render_error_page(
                    _("Missing parameter"), _("Certificate serial number parameter is mandatory.")
                )
            document_source = DocumentSource(settings.ISSUER, sn=sn)
            document = Document(document_source)
            verified = document.verify()
            # document.verify() returns False if verification failed
            # and None upon another error
            if verified != False:
                _id = document.get_id()
                if mime:
                    signature = document.get_signature()
                    body = document.get_body()
                    message = MIMESignedMessage(settings.SMTP_USERNAME, email, render_subject(_id), body, signature)
                else:
                    if not pgp:
                        body = document.get_raw_data()
                        message = TextMessage(settings.SMTP_USERNAME, email, render_subject(_id), body)
                if pgp:
                    gnupg = GPG(gnupghome=ws_settings.GNUPG_HOME)
                    received = gnupg.receive_keys(pgp, always_trust=True)
                    if received:
                        if mime:
                            encrypted = gnupg.encrypt(message.as_string(), pgp, always_trust=True)
                            if encrypted:
                                message = MIMEEncryptedMessage(
                                    settings.SMTP_USERNAME, email, render_subject(_id), str(encrypted)
                                )
                            else:
                                return self._render_error_page(
                                    _("Something went wrong"), _("Encryption problem. Sorry for the inconvenience!")
                                )
                        else:
                            message = make_document(document.get_raw_data())
                            encrypted = gnupg.encrypt(message, pgp, always_trust=True, no_literal=True)
                            if encrypted:
                                message = TextMessage(
                                    settings.SMTP_USERNAME, email, render_subject(_id), str(encrypted)
                                )
                            else:
                                return self._render_error_page(
                                    _("Something went wrong"), _("Encryption problem. Sorry for the inconvenience!")
                                )
                    else:
                        return self._render_error_page(
                            _("Something went wrong"), _("Can not receive key. Sorry for the inconvenience!")
                        )

                m = Mailer(suppress_exceptions=False)
                try:
                    m.send(message)
                except MailerException:
                    return self._render_error_page(
                        _("Something went wrong"), _("Please try again later. Sorry for the inconvenience!")
                    )
                page.append(
                    render_message(
                        _("Request was completed successfully"),
                        _("Your receipt will be emailed shortly. Thank you for your patience!"),
                    )
                )
            else:
                return self._render_error_page(
                    _("Something went wrong"), _("Please try again later. Sorry for the inconvenience!")
                )
        else:
            page.append(
                render_message(
                    _("Malformed request"),
                    _(
                        "You should use POST request with Content-Type: application/x-www-form-urlencoded and appropriate parameters list."
                    ),
                )
            )
        page.append(render_footer())
        return page
コード例 #3
0
ファイル: templates.py プロジェクト: martyanov/webshop
def render_subject(cert_id):
    return "%(subject)s %(id)s" % {'subject': _('Payment receipt, reference:'),
                                   'id': cert_id}