Example #1
0
def test_valid_token_status(user):
    token = make_token(user, "valid_test")
    expired, invalid, token_user = get_token_status(token, "valid_test")

    assert not expired
    assert not invalid
    assert token_user == user
Example #2
0
def send_activation_token(user):
    """Sends the activation token to the user's email address.

    :param user: The user object to whom the email should be sent.
    """
    token = make_token(user=user, operation="activate_account")
    send_email(subject=_("Account Activation"),
               recipients=[user.email],
               text_body=render_template("email/activate_account.txt",
                                         user=user,
                                         token=token),
               html_body=render_template("email/activate_account.html",
                                         user=user,
                                         token=token))
Example #3
0
def send_reset_token(user):
    """Sends the reset token to the user's email address.

    :param user: The user object to whom the email should be sent.
    """
    token = make_token(user=user, operation="reset_password")
    send_email(subject=_("Password Recovery Confirmation"),
               recipients=[user.email],
               text_body=render_template("email/reset_password.txt",
                                         user=user,
                                         token=token),
               html_body=render_template("email/reset_password.html",
                                         user=user,
                                         token=token))
Example #4
0
def send_activation_token(user):
    token = make_token(user=user, operation="activate_account")
    send_email(
        subject=_("Account Activation"),
        recipients=[user.email],
        text_body=render_template(
            "email/activate_account.txt",
            user=user,
            token=token
        ),
        html_body=render_template(
            "email/activate_account.html",
            user=user,
            token=token
        )
    )
Example #5
0
def send_reset_token(user):
    token = make_token(user=user, operation="reset_password")
    send_email(
        subject=_("Password Recovery Confirmation"),
        recipients=[user.email],
        text_body=render_template(
            "email/reset_password.txt",
            user=user,
            token=token
        ),
        html_body=render_template(
            "email/reset_password.html",
            user=user,
            token=token
        )
    )
Example #6
0
def send_activation_token(user_id, username, email):
    """Sends the activation token to the user's email address.

    :param user_id: The user id. Used to generate the reset token.
    :param username: The username to whom the email should be sent.
    :param email:  The email address of the user
    """
    token = make_token(user_id=user_id, operation="activate_account")
    send_email(subject=_("Account Activation"),
               recipients=[email],
               text_body=render_template("email/activate_account.txt",
                                         username=username,
                                         token=token),
               html_body=render_template("email/activate_account.html",
                                         username=username,
                                         token=token))
Example #7
0
def send_reset_token(user_id, username, email):
    """Sends the reset token to the user's email address.

    :param user_id: The user id. Used to generate the reset token.
    :param username: The username to whom the email should be sent.
    :param email:  The email address of the user
    """
    token = make_token(user_id=user_id, operation="reset_password")
    send_email(subject=_("Password Recovery Confirmation"),
               recipients=[email],
               text_body=render_template("email/reset_password.txt",
                                         username=username,
                                         token=token),
               html_body=render_template("email/reset_password.html",
                                         username=username,
                                         token=token))
Example #8
0
def send_activation_token(user):
    """Sends the activation token to the user's email address.

    :param user: The user object to whom the email should be sent.
    """
    token = make_token(user=user, operation="activate_account")
    send_email(
        subject=_("Account Activation"),
        recipients=[user.email],
        text_body=render_template(
            "email/activate_account.txt",
            user=user,
            token=token
        ),
        html_body=render_template(
            "email/activate_account.html",
            user=user,
            token=token
        )
    )
Example #9
0
def send_reset_token(user):
    """Sends the reset token to the user's email address.

    :param user: The user object to whom the email should be sent.
    """
    token = make_token(user=user, operation="reset_password")
    send_email(
        subject=_("Password Recovery Confirmation"),
        recipients=[user.email],
        text_body=render_template(
            "email/reset_password.txt",
            user=user,
            token=token
        ),
        html_body=render_template(
            "email/reset_password.html",
            user=user,
            token=token
        )
    )
Example #10
0
def test_make_token(user):
    token = make_token(user, "test")
    s = TimedJSONWebSignatureSerializer(current_app.config['SECRET_KEY'])
    unpacked_token = s.loads(token)
    assert user.id == unpacked_token["id"]
    assert "test" == unpacked_token["op"]
Example #11
0
def test_expired_token_status(user):
    token = make_token(user, "expired_test", -1)
    expired, invalid, token_user = get_token_status(token, "expired_test")
    assert expired
    assert not invalid
    assert not token_user
Example #12
0
def test_token_operation(user):
    token = make_token(user, "operation_test")
    expired, invalid, token_user = get_token_status(token, "invalid_op")
    assert invalid
    assert not expired
    assert not token_user
Example #13
0
def test_token_status_with_data(user):
    token = make_token(user, "test_data")
    expired, invalid, token_user, data = \
        get_token_status(token, "test_data", return_data=True)
    assert user.id == data["id"]
    assert "test_data" == data["op"]