简体   繁体   中英

How should I store login info from Pyramid application? Beaker?

I come from PHP world, and I've just started learning Pyramid framework. Currently I'm trying to figure out whats the best option to store user data.

So in PHP I coded a model that utilized php builtin sessions with combination of cookies. Cookies were only ever used, if user chose to tick 'remember me' box while logging in. So when user was logged in, a session contained data that would legitimize the login. When session expired, a check would be made for valid cookies, which would than re-create the session and extend the date till which the cookie is valid.

So here in Pyramid, I would like to do something that is similar, but possibly easier and better. I am currently interested in Beaker for Pyramid: http://beaker.readthedocs.org/en/latest/

My dilemma is, which persistence method should I use? If I'm going to use Beaker just for sessions, than I think I want to go with memcached or memory only configuration. If I want to add persistance, I definitely wanna go with mysql database thru sqlalchemy, as I'd hate to clutter the server with session files. Or I could just go with encrypted cookies in first place, and therefore even eliminate ton of work, that would have to be done with cookies additionally anyway, thus eliminating need to store session on server as well.

What do you suggest me to go with?

As this site is not intended to be mainstream thing, but rather a tool for high level clients, I don't think remember me option is really necessary, I think I pretty much want to have it on by default, therefore should I just go with Beaker Cookies based Session?

How should my pyramid development.ini configuration look like in that case?

If you want to use beaker with memcached for your sessions your config should include something like this:

config.ini:

pyramid.includes =
    pyramid_tm
    pyramid_beaker

session.type = ext:memcached
session.url = url:11211
session.lock_dir = /tmp/memcached/lock

You could use cookies instead if you want. Also you don't need to use memcached and could store as files locally on the server or in memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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