There is no reload_user function in the current version of flask-login, how to verify user information?

when I was learning flask, I came across the extension flask-login. I don"t understand the user_loader decorator very much.
query many articles / questions and answers all mentioned that the decorator user_loader assigns the decorative function to self.user_callback, and
and reloader_user is also the calling method, but I did not find the reloader_user
function in the github query flask-login. What is the replacement of the previous reloader_user implementation now? When the user is not logged in for the first time, how does
get the user"s login information if he or she has already registered? Thank you!

flask-login "s github: https://github.com/maxcountry...
related articles: http://www.voidcn.com/article...

Jun.05,2022

@login_manager.user_loader
def load_user(user_id):
    ...

add user_loader to tell flask-login that your logged-in user will get it from the load_user () function.

We analyze it in terms of not logged in and logged in.
first of all, you need to provide a User interface, like this

class MyUser(object):
    is_authenticated = False
    is_active = True
    is_anonymous = True
    def get_id():
        return None

assume that the current user is named currUser .

not logged in

at this time currUser.is_anonymous is True , indicating an anonymous user.
when a user submits an account password to log in, you have to verify it from the database. After passing

  • currUser.is_authenticated becomes True
  • currUser.is_anonymous becomes False
  • currUser.get_id () returns the user's login account

then call flask_login.login_user (currUser) to tell flask-login that the user has logged in successfully.

logged in

refer to the current user with flask_login.current_user variable, and call flask_login.logout_user ()

when you log out.

I've struggled with this problem before, and this article will make it clear to you: https://codeshelper.com/q/10...

.
Menu