Add _debug facility to the Page class
[cascardo/ipsilon.git] / ipsilon / login / common.py
index 416ff31..4888060 100755 (executable)
@@ -37,7 +37,7 @@ class LoginManagerBase(PluginObject):
     def auth_successful(self, username):
         # save ref before calling UserSession login() as it
         # may regenerate the session
-        ref = '/idp'
+        ref = cherrypy.config.get('base.mount', "") + '/'
         if 'referral' in cherrypy.session:
             ref = cherrypy.session['referral']
 
@@ -51,8 +51,8 @@ class LoginManagerBase(PluginObject):
         if self.next_login:
             return self.redirect_to_path(self.next_login.path)
 
-        # FIXME: show an error page instead
-        raise cherrypy.HTTPError(401)
+        ref = cherrypy.config.get('base.mount', "") + '/unauthorized'
+        raise cherrypy.HTTPRedirect(ref)
 
 
 class LoginPageBase(Page):
@@ -78,12 +78,15 @@ class Login(Page):
         self._site[FACILITY] = loader.get_plugin_data()
         plugins = self._site[FACILITY]
 
+        available = plugins['available'].keys()
+        self._debug('Available login managers: %s' % str(available))
+
         prev_obj = None
-        for item in plugins['available']:
-            self._log('Login plugin available: %s' % item)
-            if item not in plugins['whitelist']:
+        for item in plugins['whitelist']:
+            self._debug('Login plugin in whitelist: %s' % item)
+            if item not in plugins['available']:
                 continue
-            self._log('Login plugin enabled: %s' % item)
+            self._debug('Login plugin enabled: %s' % item)
             plugins['enabled'].append(item)
             obj = plugins['available'][item]
             if prev_obj:
@@ -95,10 +98,6 @@ class Login(Page):
                 obj.set_config(plugins['config'][item])
             self.__dict__[item] = obj.get_tree(self._site)
 
-    def _log(self, fact):
-        if cherrypy.config.get('debug', False):
-            cherrypy.log(fact)
-
     def root(self, *args, **kwargs):
         if self.first_login:
             raise cherrypy.HTTPRedirect('%s/login/%s' %