用 Flask-login 来作登陆处理,经常(但不是一直)爆出未登录异常,求经验分享...

2014-11-27 17:00:03 +08:00
 gkiwi
在局域网测试,一般都是ok的.但是以上服务器测试,手机的app就经常爆出这个问题.

而在局域网内,app端更换自己的局域网ip **一定**会爆出这个问题,在此种情境下,我print 了cookies和session,发现都没变.

大家是怎么处理这块的?
谢谢.
2615 次点击
所在节点    Flask
3 条回复
hahastudio
2014-11-27 17:12:57 +08:00
没用过 Flask

看文档的话
https://flask-login.readthedocs.org/en/latest/#session-protection
提到了默认是 basic
glasslion
2014-11-27 17:17:50 +08:00
You can configure session protection on the LoginManager, and in the app’s configuration. If it is enabled, it can operate in either basic or strong mode. To set it on the LoginManager, set the session_protection attribute to "basic" or "strong":

login_manager.session_protection = "strong"
Or, to disable it:

login_manager.session_protection = None
By default, it is activated in "basic" mode. It can be disabled in the app’s configuration by setting the SESSION_PROTECTION setting to None, "basic", or "strong".

When session protection is active, each request, it generates an identifier for the user’s computer (basically, the MD5 hash of the IP address and user agent). If the session does not have an associated identifier, the one generated will be stored. If it has an identifier, and it matches the one generated, then the request is OK.
gkiwi
2014-11-27 17:45:34 +08:00
@hahastudio
@glasslion

谢谢两位!仔细看了下,原来配置文件里面SESSION_PROTECTION被设置成了"strong"..

非常感谢!!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/149730

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX