F
F
ForSureN12019-11-09 14:46:55
SQLite
ForSureN1, 2019-11-09 14:46:55

When you restart the web application, authorization does not work (Invalid data)?

Good afternoon.
I have a web application, it has registration and authorization, in registration I enter a nickname, email, password, the
data enters the database (the password is hashed), but if I immediately enter the data, then I will get to the desired page , but if I restart the application and try to log in again, it will tell me that I entered incorrect data, I don’t know how to solve this problem:
Here is the authorization code:

@app.route('/login/', methods=['post', 'get'])
def login():
    if current_user.is_authenticated:
        print("true")
        return redirect(url_for('admin'))
    form = LoginForm(request.form)
    if form.validate_on_submit():
        print("true")
        user = db.session.query(Users).filter(Users.username == form.username.data).first()
        if user and user.check_password(form.password.data):
            print("true")
            login_user(user, remember=form.remember.data)
            return redirect(url_for('admin'))
        flash("Invalid username/password", 'error')
        return redirect(url_for('login'))
    return render_template('login.html', form=form)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2019-11-09
@pcdesign

methods=['post', 'get']
It is necessary to write in capital letters And it is necessary to clearly track when the request is POST, and when it is GET

def login():
    if current_user.is_authenticated:
        print("true")
        return redirect(url_for('admin'))
    form = LoginForm(request.form)
    if request.method == 'POST':   
        if form.validate_on_submit():
            # Что-то делаем с данными, которые пришли от юзера

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question