from ipsilon.util.plugin import PluginInstaller
from ipsilon.info.common import Info
from ipsilon.util.cookies import SecureCookie
-from ipsilon.util.trans import Transaction
import cherrypy
def __init__(self):
super(LoginManagerBase, self).__init__()
+ self._site = None
self.path = '/'
self.next_login = None
self.info = None
def get_tree(self, site):
raise NotImplementedError
+ @property
+ def is_enabled(self):
+ if self._site:
+ return self in self._site[FACILITY]['enabled']
+ return False
+
def enable(self, site):
+ self._site = site
plugins = site[FACILITY]
if self in plugins['enabled']:
return
self.info = root.info
def disable(self, site):
+ self._site = site
plugins = site[FACILITY]
if self not in plugins['enabled']:
return
return self._template(self.formtemplate, **context)
def root(self, *args, **kwargs):
- self.trans = Transaction('login', **kwargs)
+ self.trans = self.get_valid_transaction('login', **kwargs)
op = getattr(self, cherrypy.request.method, self.GET)
if callable(op):
return op(*args, **kwargs)
"next_url": next_url,
"username": username,
"login_target": target,
+ "cancel_url": '%s/login/cancel?%s' % (self.basepath,
+ self.trans.get_GET_arg()),
}
context.update(kwargs)
if self.trans is not None:
def __init__(self, *args, **kwargs):
super(Login, self).__init__(*args, **kwargs)
+ self.cancel = Cancel(*args, **kwargs)
self.first_login = None
self.info = Info(self._site)
def root(self, *args, **kwargs):
if self.first_login:
- trans = Transaction('login', **kwargs)
+ trans = self.get_valid_transaction('login', **kwargs)
redirect = '%s/login/%s?%s' % (self.basepath,
self.first_login.path,
trans.get_GET_arg())
return self._template('logout.html', title='Logout')
+class Cancel(Page):
+
+ def GET(self, *args, **kwargs):
+
+ session = UserSession()
+ session.logout(None)
+
+ # return to the caller if any
+ transdata = self.get_valid_transaction('login', **kwargs).retrieve()
+ if 'login_return' not in transdata:
+ raise cherrypy.HTTPError(401)
+ raise cherrypy.HTTPRedirect(transdata['login_return'])
+
+ def root(self, *args, **kwargs):
+ op = getattr(self, cherrypy.request.method, self.GET)
+ if callable(op):
+ return op(*args, **kwargs)
+
+
class LoginMgrsInstall(object):
def __init__(self):