Esempio n. 1
0
    def get(self, token):
        if current_user.is_authenticated:
            return redirect(url_for("main.index"))

        user = User.verify_token(token)

        if user is None:
            flash(
                "Invalid or expired password reset token. Request a new one below.",
                "warning",
            )
            return redirect(url_for("users.reset_password_request"))
        else:
            new_token = user.generate_password_reset_token()
            return render_template("users/reset_password.html",
                                   token=new_token,
                                   title="Reset Password")
Esempio n. 2
0
    def get(self, token):
        if current_user.is_authenticated:
            return redirect(url_for("main.index"))

        user = User.verify_token(token)

        if user is None:
            flash(
                "Invalid or expired password reset token. Request a new one below.",
                "warning",
            )
            return redirect(url_for("users.reset_password_request"))
        else:
            new_token = user.generate_password_reset_token()
            return render_template(
                "users/reset_password.html", token=new_token, title="Reset Password"
            )
Esempio n. 3
0
    def get(self, token):
        if current_user.is_authenticated and current_user.email_confirmed:
            return redirect(url_for("main.index"))

        user = User.verify_token(token)

        if user is None:
            flash("Invalid or expired email confirmation token.", "danger")
        elif user.email_confirmed_at:
            flash("This user has already been verified.", "warning")
        else:
            user.active = True
            user.email_confirmed_at = datetime.datetime.now()
            db.session.commit()

            flash("Your email has been verified!", "success")

        return redirect(url_for("main.index"))
Esempio n. 4
0
    def post(self, token):
        if current_user.is_authenticated:
            return redirect(url_for("main.index"))

        user = User.verify_token(token)
        form = ResetPasswordForm()
        if form.validate_on_submit():
            user.password = bcrypt.generate_password_hash(
                form.password.data).decode("utf-8")
            db.session.commit()

            flash("Your password has been reset!", "success")

            return jsonify({"success": True})
        else:
            errors = form.errors
            if user is None:
                errors["token"] = ["Invalid token."]

            return jsonify(errors=form.errors), 422
Esempio n. 5
0
    def post(self, token):
        if current_user.is_authenticated:
            return redirect(url_for("main.index"))

        user = User.verify_token(token)
        form = ResetPasswordForm()
        if form.validate_on_submit():
            user.password = bcrypt.generate_password_hash(form.password.data).decode(
                "utf-8"
            )
            db.session.commit()

            flash("Your password has been reset!", "success")

            return jsonify({"success": True})
        else:
            errors = form.errors
            if user is None:
                errors["token"] = ["Invalid token."]

            return jsonify(errors=form.errors), 422