简体   繁体   English

使用mod_wsgi保持用户登录

[英]Keep user signed in using mod_wsgi

I'm developing a web app using my own framework that I created using mod_wsgi. 我正在使用使用mod_wsgi创建的自己的框架来开发Web应用程序。

I want to avoid using dependencies such as Django or Flask, just to have a short script, It actually won't be doing much. 我想避免使用诸如Django或Flask之类的依赖项,只是为了编写简短的脚本,实际上并不会做很多事情。

I have managed to authenticate user using LDAP, from a login page, the problem is that I don't want the user to authenticate every time a action requires authorization, but I don't know how to keep user logged in. 我已经从登录页面设法使用LDAP对用户进行身份验证,问题是我不希望用户每次操作需要授权时都对用户进行身份验证,但是我不知道如何保持用户登录。

Should I use the cookies? 我应该使用Cookie吗? If so, what would be the best method to keep identification in cookies? 如果是这样,最好的方法是在cookie中保留身份? What are my options? 我有什么选择?

The best (read: easiest) way to go about this is with session variables. 最好的(阅读:最简单的)方法是使用会话变量。 That said, in lieu of session variable functionality you would get with a framework, you can implement your own basic system. 就是说,代替您可以使用框架获得的会话变量功能,您可以实现自己的基本系统。

1) Generate a random Session id 1)产生一个随机的Session ID

2) send a cookie to browser 2)将Cookie发送到浏览器

3) Json or pickle encode your variables 3)Json或pickle编码您的变量

4a) save encoded string to key-value storage system like redis or memcached with session if as the key, or 4a)将编码的字符串保存到键值存储系统(例如redis或具有会话的内存缓存)中,作为键,或者

4b) save it to a file on the server preferably in /tmp/ 4b)最好将其保存到服务器上的文件/ tmp /中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM