Cleaning code
This commit is contained in:
parent
a8f454220a
commit
3a4aa06c1c
4 changed files with 17 additions and 57 deletions
|
|
@ -21,7 +21,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from cuchulu.libraries.pages import Pages
|
from cuchulu.libraries.pages import Pages
|
||||||
from cuchulu.libraries.urls import add_get_parameters
|
from cuchulu.libraries.urls import add_get_parameters
|
||||||
from cuchulu.libraries.sessions import get_session
|
#from cuchulu.libraries.sessions import get_session
|
||||||
|
from cuchulu.libraries.sessionplugin import get_session
|
||||||
from cuchulu.libraries.i18n import I18n, PGetText
|
from cuchulu.libraries.i18n import I18n, PGetText
|
||||||
from cuchulu.libraries.httputils import GetPostFiles
|
from cuchulu.libraries.httputils import GetPostFiles
|
||||||
from bottle import request
|
from bottle import request
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from cuchulu.modules.admin2.models.admin import UserAdmin2
|
from cuchulu.modules.admin2.models.admin import UserAdmin2
|
||||||
from bottle import request
|
from bottle import request
|
||||||
from cuchulu.libraries.sessions import get_session
|
#from cuchulu.libraries.sessions import get_session
|
||||||
|
from cuchulu.libraries.sessionplugin import get_session
|
||||||
from cuchulu.libraries.urls import redirect, make_url
|
from cuchulu.libraries.urls import redirect, make_url
|
||||||
from cuchulu.libraries.db.webmodel import WebModel
|
from cuchulu.libraries.db.webmodel import WebModel
|
||||||
import inspect
|
import inspect
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,14 @@ except ModuleNotFoundError:
|
||||||
class config:
|
class config:
|
||||||
cookie_name='cuchulu.session'
|
cookie_name='cuchulu.session'
|
||||||
key_encrypt=create_key_encrypt_256(30)
|
key_encrypt=create_key_encrypt_256(30)
|
||||||
session_opts={'session.data_dir': 'sessions', 'session.type': 'file', 'session.path': 'cuchulu'}
|
#session_opts={'session.data_dir': 'sessions', 'session.type': 'file'}
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
|
session_type='cookie'
|
||||||
|
|
||||||
|
if hasattr(config, 'session_type'):
|
||||||
|
session_type=config.session_type
|
||||||
|
|
||||||
class Session(dict):
|
class Session(dict):
|
||||||
"""Class for create sessions using itsdangerous library"""
|
"""Class for create sessions using itsdangerous library"""
|
||||||
|
|
@ -72,7 +75,7 @@ class Session(dict):
|
||||||
self.changed=False
|
self.changed=False
|
||||||
|
|
||||||
#if not max_age:
|
#if not max_age:
|
||||||
response.set_cookie(config.cookie_name, self.safe.dumps(self), path=config.session_opts['session.path'], httponly=True)
|
response.set_cookie(config.cookie_name, self.safe.dumps(self), path=config.base_url, httponly=True)
|
||||||
"""
|
"""
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.save()
|
self.save()
|
||||||
|
|
@ -207,25 +210,15 @@ class SessionPlugin(object):
|
||||||
|
|
||||||
#For compatibility with old sessions server-side style.
|
#For compatibility with old sessions server-side style.
|
||||||
|
|
||||||
|
request.session=session
|
||||||
|
|
||||||
request.environ['session']=session
|
request.environ['session']=session
|
||||||
|
|
||||||
request.environ['session'].changed=False
|
request.environ['session'].changed=False
|
||||||
|
|
||||||
rv=callback(*args, **kwargs)
|
rv=callback(*args, **kwargs)
|
||||||
|
|
||||||
#if request.environ['session'].changed:
|
|
||||||
|
|
||||||
request.environ['session'].save()
|
request.environ['session'].save()
|
||||||
|
|
||||||
"""
|
|
||||||
if session.changed:
|
|
||||||
#print('changed')
|
|
||||||
if not safe:
|
|
||||||
safe=URLSafeTimedSerializer(config.key_encrypt)
|
|
||||||
|
|
||||||
#if not max_age:
|
|
||||||
response.set_cookie(config.cookie_name, safe.dumps(session), path=config.session_opts['session.path'], httponly=True)
|
|
||||||
"""
|
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# You need install cromosoma for use this.
|
# You need install cuchulu for use this.
|
||||||
|
|
||||||
from cuchulu.libraries.db.webmodel import WebModel
|
from cuchulu.libraries.db.webmodel import WebModel
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
@ -12,6 +12,8 @@ import sys, os
|
||||||
cuchulu_root=os.path.dirname(sys.modules['cuchulu'].__file__)
|
cuchulu_root=os.path.dirname(sys.modules['cuchulu'].__file__)
|
||||||
|
|
||||||
#####
|
#####
|
||||||
|
# You can add you things here.
|
||||||
|
####
|
||||||
|
|
||||||
#Host/IP where bind the server
|
#Host/IP where bind the server
|
||||||
|
|
||||||
|
|
@ -31,10 +33,6 @@ allowed_ips=[]
|
||||||
|
|
||||||
theme='default'
|
theme='default'
|
||||||
|
|
||||||
#Base directory for save modules
|
|
||||||
|
|
||||||
#base_modules="modules"
|
|
||||||
|
|
||||||
#Type server used for connect to the internet...
|
#Type server used for connect to the internet...
|
||||||
# With bottle 0.13 is better use gunicorn
|
# With bottle 0.13 is better use gunicorn
|
||||||
|
|
||||||
|
|
@ -44,10 +42,6 @@ server_used="gunicorn"
|
||||||
|
|
||||||
default_module="welcome"
|
default_module="welcome"
|
||||||
|
|
||||||
#Modules with permissions to access for users
|
|
||||||
|
|
||||||
#modules=['cuchulu.modules.welcome']
|
|
||||||
|
|
||||||
# For apps using own app objects
|
# For apps using own app objects
|
||||||
|
|
||||||
apps={'welcome': ['cuchulu.modules.welcome', 'welcome_app', '/'], 'lang': ['cuchulu.modules.lang', '', '']}
|
apps={'welcome': ['cuchulu.modules.welcome', 'welcome_app', '/'], 'lang': ['cuchulu.modules.lang', '', '']}
|
||||||
|
|
@ -60,53 +54,24 @@ base_url='/'
|
||||||
|
|
||||||
session_enabled=True
|
session_enabled=True
|
||||||
|
|
||||||
#Variables for beaker sessions
|
#Variables for sessions
|
||||||
|
|
||||||
cookie_name = 'cuchulu.session'
|
cookie_name = 'cuchulu.session'
|
||||||
|
|
||||||
domain_url='http://localhost:5000'
|
domain_url='http://localhost:5000'
|
||||||
|
|
||||||
portal_email='Portal name'
|
portal_email='Cuchulu'
|
||||||
|
|
||||||
#Keep this variable and don't show to anybody
|
#Keep this variable and don't show to anybody
|
||||||
|
|
||||||
key_encrypt="im smoking fool"
|
key_encrypt="im smoking fool"
|
||||||
|
|
||||||
# Options for use redis for sessions, more scalable.
|
|
||||||
|
|
||||||
"""
|
|
||||||
session_opts = {
|
|
||||||
|
|
||||||
'session.path': base_url,
|
|
||||||
'session.key': cookie_name,
|
|
||||||
'session.type': 'redis',
|
|
||||||
'session.host': 'localhost',
|
|
||||||
'session.port': 6379,
|
|
||||||
'session.db': 0
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Options for use files for sessions
|
|
||||||
|
|
||||||
session_opts = {
|
|
||||||
|
|
||||||
'session.path': base_url,
|
|
||||||
'session.key': cookie_name,
|
|
||||||
'session.type': 'file',
|
|
||||||
'session.data_dir': './sessions',
|
|
||||||
'session.auto': False,
|
|
||||||
'session.secret': key_encrypt,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#Can be absolute or relative
|
|
||||||
|
|
||||||
media_url='/'
|
media_url='/'
|
||||||
|
|
||||||
#Use this feature in development, you should change it in production.
|
#Use this feature in development, you should change it in production.
|
||||||
|
|
||||||
yes_static=True
|
yes_static=True
|
||||||
|
|
||||||
#Database mysql config, if you want anything...
|
#Database mysql config.
|
||||||
|
|
||||||
#WebModel.connections={'default': {'name': 'default', 'host': 'localhost', 'user': 'root', 'password': '', 'db': 'example', 'charset': 'utf8mb4', 'set_connection': False} }
|
#WebModel.connections={'default': {'name': 'default', 'host': 'localhost', 'user': 'root', 'password': '', 'db': 'example', 'charset': 'utf8mb4', 'set_connection': False} }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue