Add auto-auth requirement to all admin pages
[cascardo/ipsilon.git] / ipsilon / util / page.py
index 10f10aa..f98b2d9 100755 (executable)
@@ -42,6 +42,8 @@ class Page(Log):
         self.basepath = cherrypy.config.get('base.mount', "")
         self.user = None
         self._is_form_page = form
+        self.default_headers = dict()
+        self.auth_protect = False
 
     def _compare_urls(self, url1, url2):
         u1 = unquote(url1)
@@ -52,11 +54,16 @@ class Page(Log):
 
     def __call__(self, *args, **kwargs):
         # pylint: disable=star-args
+        cherrypy.response.headers.update(self.default_headers)
+
         self.user = UserSession().get_user()
 
+        if self.auth_protect and self.user.is_anonymous:
+            raise cherrypy.HTTPError(401)
+
         if len(args) > 0:
             op = getattr(self, args[0], None)
-            if callable(op) and getattr(self, args[0]+'.exposed', None):
+            if callable(op) and getattr(op, 'public_function', None):
                 return op(*args[1:], **kwargs)
         else:
             if self._is_form_page:
@@ -98,7 +105,7 @@ class Page(Log):
         return t.render(**m)
 
     def default(self, *args, **kwargs):
-        raise cherrypy.HTTPError(404)
+        raise cherrypy.NotFound()
 
     def add_subtree(self, name, page):
         self.__dict__[name] = page