0

I have a login page that uses a custom FlaskForm (using WTForms). If a user enters the correct credentials, a PostgreSQL database is successfully queried (using flask-sqlalchemy) to see if a user with that name and (hashed) password exists. If there is such a user, login_user(user) is ran, and the user should be redirected to the homepage of my site.

I have implemented flask-login (as per the online documentation), but when a user provides valid credentials for logging in, they are redirected back to the login page (as if they had not provided valid credentials). I am using Google Chrome.

Below are the files/classes I have imported in my file application.py, and below those is a screenshot of the command line output when a user tries to log in and the situation in the above paragraph occurs. A list of the versionsof what I am using is below the screenshot.

I have determined that after redirecting to the homepage, the current_user is of type AnonymousUserMixin (even though current user in the login function is of type User (which I have defined, inheriting all methods from UserMixin).

Thank you in advance for your help!

Imports:

import os from flask import flash, Flask, session, redirect, render_template, request, url_for from flask_bootstrap import Bootstrap from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user from flask_session import Session from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker from forms import LoginForm, RegistrationForm import bcrypt

Command Line Output of Above Issue Command Line Output from Above Linked Image:

127.0.0.1 - - [15/Jun/2020 18:42:35] "GET /login HTTP/1.1" 200 -

127.0.0.1 - - [15/Jun/2020 18:42:48] "POST /login HTTP/1.1" 302 -

127.0.0.1 - - [15/Jun/2020 18:42:48] "GET / HTTP/1.1" 302 -

127.0.0.1 - - [15/Jun/2020 18:42:48] "GET /login?next=%2F HTTP/1.1" 200 -

Versions:

Windows 10 bcrypt 3.1.7 email-validator 1.1.1 Python 3.8.2 Flask 1.1.2 Flask-WTF 0.14.3 Flask-SQLAlchemy 2.4.3 Flask-Session 0.3.2 Flask-Login 0.5.0 Flask-Bootstrap WTForms 2.3.1 SQLAlchemy 1.3.16 mysql-connector-python 8.0.19 mysql-client 0.0.1 Jinja2 2.11.2 itsdangerous 1.1.0

You must log in to answer this question.

Browse other questions tagged .