Example #1
0
def change_password():
    form = NewPasswordForm()
    if form.validate_on_submit():
        current_user.set_password(form.password.data)
        db.session.add(current_user)
        db.session.commit()

        flash("Password changed successfully!", "success")
        return redirect(url_for("core.profile"))
    else:
        flash_errors(form)
    return render_template("core/change_password.html", form=form)
Example #2
0
def reset_password(username, key):
    user = User.query.filter_by(username=username, activation_key=key, active=True).first_or_404()
    form = NewPasswordForm()
    if form.validate_on_submit():
        user.activate()

        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()

        flash("Password changed successfully!", "success")
        return redirect(url_for("core.home"))
    else:
        flash_errors(form)
    return render_template("core/reset_password.html", form=form)