Fix exposed functions
[cascardo/ipsilon.git] / ipsilon / util / page.py
index aad91fc..1548d47 100755 (executable)
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from ipsilon.util.log import Log
 from ipsilon.util.user import UserSession
 from urllib import unquote
 import cherrypy
@@ -33,7 +34,17 @@ def admin_protect(fn):
     return check
 
 
-class Page(object):
+def auth_protect(fn):
+    def check(self, *args, **kwargs):
+        if UserSession().get_user().is_anonymous:
+            raise cherrypy.HTTPRedirect(self.basepath)
+        else:
+            return fn(self, *args, **kwargs)
+
+    return check
+
+
+class Page(Log):
     def __init__(self, site, form=False):
         if 'template_env' not in site:
             raise ValueError('Missing template environment')
@@ -55,7 +66,7 @@ class Page(object):
 
         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:
@@ -96,10 +107,6 @@ class Page(object):
         m.update(kwargs)
         return t.render(**m)
 
-    def _debug(self, fact):
-        if cherrypy.config.get('debug', False):
-            cherrypy.log(fact)
-
     def default(self, *args, **kwargs):
         raise cherrypy.HTTPError(404)