Exemple #1
0
def email_password_change_email(user, new_email=None, password_change=False):
    """Queues a system email for email or password change notification."""
    from r2.lib.pages import EmailPasswordChangeEmail
    token = make_reset_token(AccountRecoveryToken, user, issue_limit=1)
    if not token:
        return False

    passlink = token.make_token_url()
    if not passlink:
        return False

    g.log.info("Generated %s: %s", AccountRecoveryToken.__name__, passlink)
    signer = MessageSigner(g.secrets["outbound_url_secret"])
    signature = base64.urlsafe_b64encode(
        signer.make_signature(_force_unicode(passlink),
                              max_age=timedelta(days=180)))
    email_kind = Email.Kind.EMAIL_CHANGE
    if password_change:
        email_kind = Email.Kind.PASSWORD_CHANGE
    _system_email(
        user.email,
        EmailPasswordChangeEmail(
            user=user,
            new_email=new_email,
            passlink=passlink,
            email_kind=email_kind,
            signature=signature,
        ).render(style='email'),
        email_kind,
        reply_to=g.support_email,
    )
    return True
Exemple #2
0
def email_password_change_email(user, new_email=None, password_change=False):
    """Queues a system email for email or password change notification."""
    from r2.lib.pages import EmailPasswordChangeEmail
    token = make_reset_token(AccountRecoveryToken, user, issue_limit=1)
    if not token:
        return False

    passlink = token.make_token_url()
    if not passlink:
        return False

    g.log.info("Generated %s: %s", AccountRecoveryToken.__name__, passlink)
    signer = MessageSigner(g.secrets["outbound_url_secret"])
    signature = base64.urlsafe_b64encode(
        signer.make_signature(
            _force_unicode(passlink),
            max_age=timedelta(days=180))
    )
    email_kind = Email.Kind.EMAIL_CHANGE
    if password_change:
        email_kind = Email.Kind.PASSWORD_CHANGE
    _system_email(
        user.email,
        EmailPasswordChangeEmail(
            user=user,
            new_email=new_email,
            passlink=passlink,
            email_kind=email_kind,
            signature=signature,
        ).render(style='email'),
        email_kind,
        reply_to=g.support_email,
    )
    return True
Exemple #3
0
def password_email(user):
    """For resetting a user's password."""
    from r2.lib.pages import PasswordReset
    token = make_reset_token(PasswordResetToken, user, issue_limit=3)
    if not token:
        return False

    passlink = token.make_token_url()
    if not passlink:
        return False

    g.log.info("Generated %s: %s for user %s", PasswordResetToken.__name__,
               passlink, user.name)
    signer = MessageSigner(g.secrets["outbound_url_secret"])
    signature = base64.urlsafe_b64encode(
        signer.make_signature(_force_unicode(passlink),
                              max_age=timedelta(days=180)))
    _system_email(
        user.email,
        PasswordReset(
            user=user,
            passlink=passlink,
            signature=signature,
        ).render(style='email'),
        Email.Kind.RESET_PASSWORD,
        reply_to=g.support_email,
        user=user,
    )
    return True
Exemple #4
0
def password_email(user):
    """For resetting a user's password."""
    from r2.lib.pages import PasswordReset
    token = make_reset_token(PasswordResetToken, user, issue_limit=3)
    if not token:
        return False

    passlink = token.make_token_url()
    if not passlink:
        return False

    g.log.info("Generated %s: %s for user %s",
               PasswordResetToken.__name__,
               passlink,
               user.name)
    signer = MessageSigner(g.secrets["outbound_url_secret"])
    signature = base64.urlsafe_b64encode(
        signer.make_signature(
            _force_unicode(passlink),
            max_age=timedelta(days=180))
    )
    _system_email(
        user.email,
        PasswordReset(
            user=user,
            passlink=passlink,
            signature=signature,
        ).render(style='email'),
        Email.Kind.RESET_PASSWORD,
        reply_to=g.support_email,
        user=user,
    )
    return True