flask_login 提供了用戶會話管理,即登入和登出,用戶信息是一個 user 對象
- 使用 login_required 裝飾器
If you decorate a view with this, it will ensure that the current user is logged in and authenticated before calling the actual view.
在一個視圖函數(shù)被調(diào)用前,需要先進(jìn)行登錄認(rèn)證 - current_user 當(dāng)前登錄的用戶,生存期為整個會話過程
current_user.is_authenticated 判斷是否登錄 - login_user 登錄一個用戶
參數(shù) user 是一個對象,remember 在cookie過期后仍然記住該用戶 - logout_user 登出一個用戶
- UserMixin 包含了 user 對象所需要的基本方法
- LoadManager 管理器,進(jìn)行一些設(shè)置,如登錄視圖,登出視圖,安全級別,登錄提示等