Beispiel #1
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RequestResetForm()

    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        token = user.get_reset_token()
        send_reset_email(user, 'mail/reset', token=token, username=user.username)
        flash('An email has been sent with instructions to reset your password', 'info')
        return redirect(url_for('users.login'))
    return render_template('reset_request.html', title='Reset Password', form=form)
Beispiel #2
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash(
            'An email has been sent with instructions to reset your password.',
            'info')
        return redirect(url_for('users.login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Beispiel #3
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(Email=form.email.data).first()
        # Call the function that will generate the email and token for the reset password.
        send_reset_email(user)
        flash("An email has been sent you can reset your email now.",
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset-request.html',
                           title='Reset Password',
                           form=form)
Beispiel #4
0
def unsubscribe():
    form = RequestResetForm()

    if form.validate_on_submit():
        email = MailingList.query.filter_by(
            email=form.email.data.lower()).first()

        if email:
            database.session.delete(email)
            database.session.commit()
            flash("You have successfully unsubscribed!", "success")
        else:
            flash("Email does not exist!", "danger")

    return render_template("unsubscribe.html", form=form)
Beispiel #5
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))

    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(form.email.data).first()
        send_reset_email(user)
        flash(
            "An email has been sent with instructions to reset your password",
            "info")
        return redirect(url_for("users.login"))
    return render_template("reset_request.html",
                           title="Reset Password",
                           form=form)
Beispiel #6
0
def reset_request():
    # check if user is logged in
    if current_user.is_authenticated:
        return redirect(url_for('users.account'))
    # create form
    form = RequestResetForm()
    # if form is submitted, get the user with that email
    # Send them an email to reset password
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_reset_email(user)
        flash('An email has been sent to you to reset your password', 'info')
        return redirect(url_for('users.login'))
    return render_template('reset_request.html',
                           title='Reset Request',
                           form=form)
Beispiel #7
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))

    form = RequestResetForm()

    if form.validate_on_submit():
        if form.validate_email(form.email):
            user = User.query.filter_by(email=form.email.data.lower()).first()
            send_reset_email(user)
            flash(
                "An email to reset your password has been sent to your email!",
                "success")
            return redirect(url_for("users.login"))

        else:
            flash("Email does not exist!", "danger")

    return render_template("reset_request.html", form=form)
Beispiel #8
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    form = RequestResetForm()
    user = User.verify_reset_token(token=token)
    if user is None:
        flash(f"Token in invalid or expired", category="warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        user.password = hashed_password
        db.session.commit()
        flash(f"Password updated successfully", category="success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form)
Beispiel #9
0
def reset_request():
    # We don't want the user to be logged in here
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))

    form = RequestResetForm()

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

        if user is None:
            flash('No such user exists in our database', 'warning')
            return redirect(url_for('users.login'))

        send_reset_email(user)

        flash('An email with instructions to reset your password has been sent.', 'info')
        return redirect(url_for('users.login'))

    return render_template('reset_request.html', title='Reset Password', form=form)