Exemple #1
0
def restore_password(tk):
    if current_user.is_authenticated:
        return redirect(url_for("public.home"))
    try:
        decoded_token = jwtToken.decode(tk,
                                        oct_data,
                                        do_verify=True,
                                        do_time_check=True)
    except JWTDecodeError:
        flash("Password reset link has expired.", "warning")
        return redirect(url_for("public.home"))
    user = User.query.filter_by(email=decoded_token["email"]).first()
    if not user:
        flash("Can't find any matching user.", "warning")
        return render_template("public/home")
    form = RestorePasswordForm(request.form)
    if not form.validate_on_submit():
        # flash("Unable to update your password, please type in your password again.", "warning")
        return render_template("public/restore_password.html",
                               form=form,
                               email=decoded_token["email"])
    else:
        User.update(self=user,
                    password=bcrypt.generate_password_hash(form.password.data))
        flash("Password updated.", "success")
    return redirect(url_for("public.home"))
Exemple #2
0
 def set_password(self, password):
     """Set password."""
     self.password = bcrypt.generate_password_hash(password)