mercredi 4 avril 2018

Flask_Login information

I want to know how to I can block the user to return to a page when he is logged in ussing flask_login. Basically a redirect to logged page when the user(logged) return the page header ...

@app.route("/login", methods=["POST","GET"])
def login():    
    if current_user.is_authenticated:
        return (redirect(url_for("inicio")))
    else:
        form = LoginForm()
        if form.validate_on_submit():                                                                                                                                           
            print(form.username.data)
            print(form.password.data)    
            user = User.query.filter_by(username=form.username.data).first()
            if user and user.password == form.password.data:
                #It's ok, user login
                login_user(user)                    
                return redirect(url_for("inicio"))
            else:
                #user no can login/ pass or user incorrects
                flash("Dados incorretos.")    

    return render_template("app/login.html", form=form)

Yes, I'm probably making correctly but... when I return to login page across the header (return page) of the browser I need to refresh the page to return to logged in page...




Aucun commentaire:

Enregistrer un commentaire