Add server-install plugin configuration support
[cascardo/ipsilon.git] / ipsilon / login / common.py
index 5879fda..d290521 100755 (executable)
@@ -20,6 +20,7 @@
 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
 import cherrypy
 
 
@@ -34,7 +35,7 @@ class LoginManagerBase(PluginObject):
         base = cherrypy.config.get('base.mount', "")
         raise cherrypy.HTTPRedirect('%s/login/%s' % (base, path))
 
-    def auth_successful(self, username):
+    def auth_successful(self, username, userdata=None):
         # save ref before calling UserSession login() as it
         # may regenerate the session
         session = UserSession()
@@ -43,6 +44,12 @@ class LoginManagerBase(PluginObject):
             ref = cherrypy.config.get('base.mount', "") + '/'
 
         session.login(username)
+
+        # Save additional data provided by the login manager
+        if userdata:
+            for key in userdata:
+                session.save_data('user', key, userdata[key])
+
         raise cherrypy.HTTPRedirect(ref)
 
     def auth_failed(self):
@@ -56,9 +63,8 @@ class LoginManagerBase(PluginObject):
 
         # otherwise destroy session and return error
         if not ref:
-            ref = cherrypy.config.get('base.mount', "") + '/unauthorized'
-            # Just make sure we destroy the session
             session.logout(None)
+            raise cherrypy.HTTPError(401)
 
         raise cherrypy.HTTPRedirect(ref)
 
@@ -119,3 +125,10 @@ class Logout(Page):
     def root(self, *args, **kwargs):
         UserSession().logout(self.user)
         return self._template('logout.html', title='Logout')
+
+
+class LoginMgrsInstall(object):
+
+    def __init__(self):
+        pi = PluginInstaller(LoginMgrsInstall)
+        self.plugins = pi.get_plugins()