Added beaker como session manager again, by default is cookie based
This commit is contained in:
parent
87177ccdb5
commit
f55ba054c0
6 changed files with 36 additions and 15 deletions
|
|
@ -14,7 +14,7 @@ except:
|
|||
cookie_name='paramecio_session'
|
||||
key_encrypt=create_key_encrypt_256(30)
|
||||
|
||||
|
||||
"""
|
||||
class ParamecioSession:
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -70,6 +70,11 @@ def generate_session():
|
|||
random_text=create_key_encrypt_256(30)
|
||||
response.set_cookie(config.cookie_name, random_text, secret=config.key_encrypt, path="/")
|
||||
request.environ[config.cookie_name]={'token': random_text}
|
||||
"""
|
||||
|
||||
def generate_session():
|
||||
s=request.environ.get(config.cookie_name)
|
||||
s.invalidate()
|
||||
|
||||
def get_session():
|
||||
|
||||
|
|
@ -77,7 +82,8 @@ def get_session():
|
|||
|
||||
if config.cookie_name in request.environ:
|
||||
|
||||
return ParamecioSession()
|
||||
return request.environ.get(config.cookie_name)
|
||||
#ParamecioSession()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ import os, sys, traceback, inspect, resource
|
|||
from importlib import import_module
|
||||
from bottle import route, get, post, run, default_app, abort, request, response, static_file, load
|
||||
from settings import config, modules
|
||||
#from beaker.middleware import SessionMiddleware
|
||||
from beaker.middleware import SessionMiddleware
|
||||
from mimetypes import guess_type
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from itsdangerous import JSONWebSignatureSerializer
|
||||
from paramecio.citoplasma.keyutils import create_key_encrypt, create_key_encrypt_256, create_key
|
||||
from paramecio.citoplasma.sessions import generate_session
|
||||
#from paramecio.citoplasma.sessions import generate_session
|
||||
|
||||
#Prepare links for static.
|
||||
#WARNING: only use this feature in development, not in production.
|
||||
|
|
@ -128,7 +128,7 @@ app.add_hook('before_request', print_memory)
|
|||
|
||||
if config.session_enabled==True:
|
||||
#Create dir for sessions
|
||||
|
||||
"""
|
||||
key_encrypt=config.key_encrypt
|
||||
|
||||
if 'session.data_dir' in config.session_opts:
|
||||
|
|
@ -196,8 +196,8 @@ if config.session_enabled==True:
|
|||
app.add_hook('before_request', load_session)
|
||||
app.add_hook('after_request', save_session)
|
||||
#def
|
||||
|
||||
#app = SessionMiddleware(app, config.session_opts, environ_key=config.cookie_name)
|
||||
"""
|
||||
app = SessionMiddleware(app, config.session_opts, environ_key=config.cookie_name)
|
||||
|
||||
def run_app(app):
|
||||
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ def logout():
|
|||
|
||||
#s.save()
|
||||
|
||||
s.remove()
|
||||
s.delete()
|
||||
|
||||
if request.get_cookie("remember_login", secret=key_encrypt):
|
||||
|
||||
|
|
|
|||
|
|
@ -48,16 +48,31 @@ session_enabled=True
|
|||
|
||||
cookie_name = 'paramecio.session'
|
||||
|
||||
#More simple sessions. Save the session in a file in ./sessions directory.
|
||||
#Go back to beaker sessions
|
||||
|
||||
|
||||
session_opts = {
|
||||
'session.type': 'file',
|
||||
'session.data_dir': './sessions'
|
||||
}
|
||||
#Keep this variable and don't show to anybody
|
||||
|
||||
key_encrypt="im smoking fool"
|
||||
|
||||
session_opts = {
|
||||
#'session.domain': 'domain.com',
|
||||
'session.cookie_expires': True,
|
||||
'session.type': 'cookie',
|
||||
'session.path': '/',
|
||||
'session.auto': True,
|
||||
'session.key': cookie_name,
|
||||
'session.validate_key': key_encrypt
|
||||
}
|
||||
|
||||
"""
|
||||
session_opts = {
|
||||
'session.type': 'file',
|
||||
'session.data_dir': './sessions',
|
||||
'session.auto': true
|
||||
|
||||
}
|
||||
"""
|
||||
|
||||
cache_session_opts = {
|
||||
|
||||
}
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -19,7 +19,7 @@ setup(name='paramecio',
|
|||
url='http://paramecioproject.com/',
|
||||
packages=['paramecio'],
|
||||
include_package_data=True,
|
||||
install_requires=['bottle', 'mako', 'passlib', 'bcrypt', 'PyMySQL', 'Pillow', 'itsdangerous'],
|
||||
install_requires=['bottle', 'mako', 'passlib', 'bcrypt', 'mysqlclient', 'sqlalchemy', 'Pillow', 'beaker'],
|
||||
entry_points={'console_scripts': [
|
||||
'paramecio = paramecio.console:start',
|
||||
]},
|
||||
|
|
|
|||
0
tests/images/uploads/.tests_folder
Normal file
0
tests/images/uploads/.tests_folder
Normal file
Loading…
Add table
Add a link
Reference in a new issue