Пример #1
0
def send_recover_email(user):
    """Sends a recovery-link to the specified user objects' email address"""
    # generate recovery key
    recovery_key = SystemRandom().randint(0, (2 << 62) - 1)

    # send email
    params = {'email': user.email, 'recovery_key': str(recovery_key)}
    mailer = util.mail
    message = mailer.new(
        to=user.email,
        subject=_("Password Recovery - Brave Collective Core Services"))

    #explicitley get the text contend for the mail
    mime, content = render("brave.core.account.template.mail/lost.txt",
                           dict(params=params))
    message.plain = content

    #explicitley get the html contend for the mail
    mime, content = render("brave.core.account.template.mail/lost.html",
                           dict(params=params))
    message.rich = content

    mailer.send(message)

    # store key in DB
    PasswordRecovery(user, recovery_key).save()
Пример #2
0
    def __after__(self, result, *args, **kw):
        """Generate the JSON response and sign."""

        key = SigningKey.from_string(unhexlify(request.service.key.private),
                                     curve=NIST256p,
                                     hashfunc=sha256)

        response = Response(status=200, charset='utf-8')
        response.date = datetime.utcnow()
        response.last_modified = result.pop('updated', None)

        ct, body = render('json:', result)
        response.headers[b'Content-Type'] = str(
            ct)  # protect against lack of conversion in Flup
        response.body = body

        canon = "{req.service.id}\n{resp.headers[Date]}\n{req.url}\n{resp.body}".format(
            req=request, resp=response)
        response.headers[b'X-Signature'] = hexlify(key.sign(canon))
        log.debug("Signing response: %s", response.headers[b'X-Signature'])
        log.debug("Canonical data:\n%r", canon)

        del response.date  # TODO: This works around an odd bug of sending two Date header values.

        return response
Пример #3
0
 def add(self):
     # TODO: mpAjax mime/multipart this to save on escaping the HTML.
     # https://github.com/getify/mpAjax
     return 'json:', dict(
             title = _("Add New API Key"),
             content = render('mako:brave.core.key.template.add', dict()),
             label = dict(label=_("Add Key"), kind='btn-success')
         )
Пример #4
0
def send_recover_email(user):
    """Sends a recovery-link to the specified user objects' email address"""
    # generate recovery key
    recovery_key = SystemRandom().randint(0, (2<< 62)-1)

    # send email
    params = {'email': user.email, 'recovery_key': str(recovery_key)}
    mailer = util.mail
    message = mailer.new(to=user.email, subject=_("Password Recovery - Brave Collective Core Services"))

    #explicitley get the text contend for the mail
    mime, content = render("brave.core.account.template.mail/lost.txt", dict(params=params))
    message.plain = content

    #explicitley get the html contend for the mail
    mime, content = render("brave.core.account.template.mail/lost.html", dict(params=params))
    message.rich = content

    mailer.send(message)

    # store key in DB
    PasswordRecovery(user, recovery_key).save()
Пример #5
0
 def __after__(self, result, *args, **kw):
     """Generate the JSON response and sign."""
     
     key = SigningKey.from_string(unhexlify(request.service.key.private), curve=NIST256p, hashfunc=sha256)
     
     response = Response(status=200, charset='utf-8')
     response.date = datetime.utcnow()
     response.last_modified = result.pop('updated', None)
     
     ct, body = render('json:', result)
     response.headers[b'Content-Type'] = str(ct)  # protect against lack of conversion in Flup
     response.body = body
     
     canon = "{req.service.id}\n{resp.headers[Date]}\n{req.url}\n{resp.body}".format(
                 req = request,
                 resp = response