Exemple #1
0
def forgot_password():
    """
    Sends a reset password token to the user.
    """

    if not current_user.is_anonymous():
        return redirect(url_for("forum.index"))

    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            token = user.make_reset_token()
            send_reset_token(user, token=token)

            flash(("E-Mail sent! Please check your inbox."), "info")
            return redirect(url_for("auth.forgot_password"))
        else:
            flash(
                (
                    "You have entered an username or email that is not linked \
                with your account"
                ),
                "danger",
            )
    return render_template("auth/forgot_password.html", form=form)
Exemple #2
0
def test_send_reset_token_to_user(default_settings, user):
    """ Deliver a contact email. """

    with current_app.test_request_context():
        with mail.record_messages() as outbox:
            send_reset_token(user)

            assert len(outbox) == 1
            assert "/auth/reset-password" in outbox[0].body  # from /auth/reset-password/<token>
            assert "/auth/reset-password" in outbox[0].html
Exemple #3
0
def test_send_reset_token_to_user(default_settings, user):
    """ Deliver a contact email. """

    with current_app.test_request_context():
        with mail.record_messages() as outbox:
            send_reset_token(user)

            assert len(outbox) == 1
            # from /auth/reset-password/<token>
            assert "/auth/reset-password" in outbox[0].body
            assert "/auth/reset-password" in outbox[0].html
Exemple #4
0
def forgot_password():
    """Sends a reset password token to the user."""
    if not current_user.is_anonymous:
        return redirect(url_for("forum.index"))

    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()

        if user:
            send_reset_token(user)
            flash(_("Email sent! Please check your inbox."), "info")
            return redirect(url_for("auth.forgot_password"))
        else:
            flash(
                _("You have entered an username or email address that is "
                  "not linked with your account."), "danger")
    return render_template("auth/forgot_password.html", form=form)