我使用燒瓶登錄https://github.com/maxcountryman/flask-login和字段記得login_user似乎並不工作。燒瓶登錄會話獲取銷燬每個Apache重啓
在每次重新啓動apache之後會話都會被破壞..記住字段應該照顧這個......即使會話值被破壞了。這是很無奈......任何人知道的解決方案,請ping通..謝謝 我使用login_user作爲
login_user(user, remember=True)
我使用燒瓶登錄https://github.com/maxcountryman/flask-login和字段記得login_user似乎並不工作。燒瓶登錄會話獲取銷燬每個Apache重啓
在每次重新啓動apache之後會話都會被破壞..記住字段應該照顧這個......即使會話值被破壞了。這是很無奈......任何人知道的解決方案,請ping通..謝謝 我使用login_user作爲
login_user(user, remember=True)
如果有人有這個問題的痛苦,你必須寫功能user_loader正常。
@login_manager.user_loader
def load_user(id):
return "get the user properly and create the usermixin object"
你必須設置在用戶mixen的get_auth_token還有user_loader
class User(UserMixin):
def get_auth_token(self):
"""
Encode a secure token for cookie
"""
data = [str(self.id), self.password]
return login_serializer.dumps(data)
而且
@login_manager.token_loader
def load_token(token):
"""
Flask-Login token_loader callback.
The token_loader function asks this function to take the token that was
stored on the users computer process it to check if its valid and then
return a User Object if its valid or None if its not valid.
"""
#The Token itself was generated by User.get_auth_token. So it is up to
#us to known the format of the token data itself.
#The Token was encrypted using itsdangerous.URLSafeTimedSerializer which
#allows us to have a max_age on the token itself. When the cookie is stored
#on the users computer it also has a exipry date, but could be changed by
#the user, so this feature allows us to enforce the exipry date of the token
#server side and not rely on the users cookie to exipre.
max_age = app.config["REMEMBER_COOKIE_DURATION"].total_seconds()
#Decrypt the Security Token, data = [username, hashpass]
data = login_serializer.loads(token, max_age=max_age)
#Find the User
user = User.get(data[0])
#Check Password and return user or None
if user and data[1] == user.password:
return user
return None
兩種這些方法使用該模塊itsdangerous加密記得我cookie
from itsdangerous import URLSafeTimedSerializer
我寫了一篇博客文章中我是怎麼做到的 Flask-Login Auth Tokens
我就遇到了這個問題,但它是因爲我們在啓動時設置Flask.secret_key
到一個新的GUID。我們將其移至配置文件(每個環境的唯一ID),現在會話被保留。