X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Flogin%2Fcommon.py;h=e59085f6bfb73e7d0608fe004bf6d808e38944d7;hp=b4515508309f70bf259a5d899534de2c39745013;hb=14e8ecd7cf8ea8d342eac5c4c66b764b3a8e2dbb;hpb=a511d8ab35cc0f2872eac640ed4120766f92704a diff --git a/ipsilon/login/common.py b/ipsilon/login/common.py index b451550..e59085f 100755 --- a/ipsilon/login/common.py +++ b/ipsilon/login/common.py @@ -22,21 +22,26 @@ from ipsilon.util.page import Page from ipsilon.util.user import UserSession from ipsilon.util.plugin import PluginLoader, PluginObject from ipsilon.util.plugin import PluginInstaller +from ipsilon.info.common import Info import cherrypy +USERNAME_COOKIE = 'ipsilon_default_username' + + class LoginManagerBase(PluginObject, Log): def __init__(self): super(LoginManagerBase, self).__init__() self.path = '/' self.next_login = None + self.info = None def redirect_to_path(self, path): base = cherrypy.config.get('base.mount', "") raise cherrypy.HTTPRedirect('%s/login/%s' % (base, path)) - def auth_successful(self, username, userdata=None): + def auth_successful(self, username, auth_type=None, userdata=None): # save ref before calling UserSession login() as it # may regenerate the session session = UserSession() @@ -44,8 +49,32 @@ class LoginManagerBase(PluginObject, Log): if not ref: ref = cherrypy.config.get('base.mount', "") + '/' + if self.info: + userattrs = self.info.get_user_attrs(username) + if userdata: + userdata.update(userattrs or {}) + else: + userdata = userattrs + self.debug("User %s attributes: %s" % (username, repr(userdata))) + + if auth_type: + if userdata: + userdata.update({'auth_type': auth_type}) + else: + userdata = {'auth_type': auth_type} + session.login(username, userdata) + # save username into a cookie if parent was form base auth + if auth_type == 'password': + cherrypy.response.cookie[USERNAME_COOKIE] = username + cherrypy.response.cookie[USERNAME_COOKIE]['path'] = \ + cherrypy.config.get('base.mount', '/') + cherrypy.response.cookie[USERNAME_COOKIE]['secure'] = True + cherrypy.response.cookie[USERNAME_COOKIE]['httponly'] = True + # 15 days + cherrypy.response.cookie[USERNAME_COOKIE]['max-age'] = 1296000 + raise cherrypy.HTTPRedirect(ref) def auth_failed(self): @@ -95,6 +124,9 @@ class LoginManagerBase(PluginObject, Log): plugins['enabled'].append(self) self._debug('Login plugin enabled: %s' % self.name) + # Get handle of the info plugin + self.info = root.info + def disable(self, site): plugins = site[FACILITY] if self not in plugins['enabled']: @@ -148,6 +180,10 @@ class LoginFormBase(LoginPageBase): if self.lm.next_login is not None: next_url = self.lm.next_login.path + username = '' + if USERNAME_COOKIE in cherrypy.request.cookie: + username = cherrypy.request.cookie[USERNAME_COOKIE].value + context = { "title": 'Login', "action": '%s/%s' % (self.basepath, self.formpage), @@ -156,6 +192,7 @@ class LoginFormBase(LoginPageBase): "password_text": self.lm.password_text, "description": self.lm.help_text, "next_url": next_url, + "username": username, } context.update(kwargs) return context @@ -169,6 +206,7 @@ class Login(Page): def __init__(self, *args, **kwargs): super(Login, self).__init__(*args, **kwargs) self.first_login = None + self.info = Info(self._site) loader = PluginLoader(Login, FACILITY, 'LoginManager') self._site[FACILITY] = loader.get_plugin_data()