Fixes in sessions and admin
This commit is contained in:
parent
ba7f7d4b1f
commit
f5a9617e93
5 changed files with 38 additions and 17 deletions
|
|
@ -282,7 +282,7 @@ def start():
|
|||
|
||||
try:
|
||||
|
||||
shutil.copy(workdir+'/settings/modules.py.admin', path_settings+'/modules.py')
|
||||
shutil.copy(workdir+'/settings/modules.py', path_settings+'/modules.py')
|
||||
|
||||
except:
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,10 @@ def session_plugin(callback):
|
|||
|
||||
return wrapper
|
||||
|
||||
#class SessionPlugin2(object):
|
||||
|
||||
|
||||
|
||||
class SessionPlugin(object):
|
||||
|
||||
name = 'session'
|
||||
|
|
@ -124,7 +128,7 @@ class SessionPlugin(object):
|
|||
def __init__(self, keyword='session'):
|
||||
|
||||
self.keyword=keyword
|
||||
self.session=None
|
||||
self.session={}
|
||||
|
||||
|
||||
def setup(self, app):
|
||||
|
|
@ -140,7 +144,7 @@ class SessionPlugin(object):
|
|||
# Test if the original callback accepts a 'session' keyword.
|
||||
# Ignore it if it does not need a login handle.
|
||||
|
||||
conf = context.config.get('session') or {}
|
||||
conf = context.config.get(self.keyword) or {}
|
||||
|
||||
keyword = conf.get('keyword', self.keyword)
|
||||
|
||||
|
|
@ -152,8 +156,10 @@ class SessionPlugin(object):
|
|||
"""
|
||||
if keyword in args:
|
||||
#print(args[keyword])
|
||||
self.session=True
|
||||
|
||||
self.session[callback.__name__]=True
|
||||
else:
|
||||
self.session[callback.__name__]=False
|
||||
#print(callback.__name__)
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
|
||||
|
|
@ -177,8 +183,9 @@ class SessionPlugin(object):
|
|||
|
||||
#if 'session' in kwargs:
|
||||
#print(kwargs)
|
||||
#if self.session:
|
||||
# kwargs['session']=session
|
||||
|
||||
if self.session[callback.__name__]:
|
||||
kwargs['session']=session
|
||||
|
||||
#For compatibility with old sessions server-side style.
|
||||
|
||||
|
|
@ -186,6 +193,10 @@ class SessionPlugin(object):
|
|||
|
||||
rv=callback(*args, **kwargs)
|
||||
|
||||
#if request.environ['session'].changed:
|
||||
request.environ['session'].save()
|
||||
|
||||
"""
|
||||
if session.changed:
|
||||
#print('changed')
|
||||
if not safe:
|
||||
|
|
@ -193,6 +204,7 @@ class SessionPlugin(object):
|
|||
|
||||
#if not max_age:
|
||||
response.set_cookie(config.cookie_name, safe.dumps(session), path=config.session_opts['session.path'], httponly=True)
|
||||
"""
|
||||
|
||||
return rv
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
try:
|
||||
|
||||
from settings import config
|
||||
|
||||
except ModuleNotFoundError:
|
||||
|
||||
class config:
|
||||
base_url='/'
|
||||
domain_url='http://localhost:8080'
|
||||
media_url='/'
|
||||
yes_static=True
|
||||
|
||||
|
||||
from bottle import request, response, HTTPResponse
|
||||
import urllib.parse
|
||||
|
||||
# A modified version of bottle url for don't need set x-proxy shit for redirect...
|
||||
# A modified version of bottle url for don't need set x-proxy for redirect. Probably is not a good idea.
|
||||
|
||||
def redirect(url, code=None):
|
||||
""" Aborts execution and causes a 303 or 302 redirect, depending on
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ if hasattr(config, 'admin_folder'):
|
|||
admin_folder=config.admin_folder
|
||||
|
||||
@admin_app.get('/home', name="admin_app.home_admin")
|
||||
def home_admin():
|
||||
def home_admin(session):
|
||||
|
||||
return t.load_template('layout.phtml', title=_('Admin'), module_selected='home_admin')
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ def signup_admin(session=Session()):
|
|||
return t.load_template('signup.phtml', title=_('Signup'))
|
||||
|
||||
@admin_app.post('/login', skip=[check_login], name='admin_app.check_login_admin')
|
||||
def check_login_admin(session=Session()):
|
||||
def check_login_admin(session):
|
||||
|
||||
db=WebModel.connection()
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ def signup_insert_admin(session=Session()):
|
|||
return {'error': error, 'message': message}
|
||||
|
||||
@admin_app.get('/logout', name="admin_app.logout_admin", skip=[check_login])
|
||||
def logout_admin(session=Session()):
|
||||
def logout_admin(session):
|
||||
|
||||
if login_admin in session:
|
||||
del session['login_admin']
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
list_modules=[]
|
||||
# This a internal configuration, probably, this file will be rewrite when you create a new module with cuchulucm script.
|
||||
|
||||
from cuchulu.modules.welcome import index
|
||||
extra_apps={}
|
||||
|
||||
#from cuchulu.modules.admin2 import index
|
||||
|
||||
from cuchulu.modules.lang import index
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue