# Path: modules/user/model/session.py
# class UserSession(AbstractSession):
#     namespace = 'user'
# 
#     def isLogged(self):
#         if 'user_key' in self:
#             return True
#         else:
#             return False
# 
#     def getUser(self):
#         if 'user_key' in self:
#             user = User.get(self['user_key'])
#             if not user:
#                 raise BaseException('User with key %s not found' % (self['user_key']))
#             return user
#         return False
# 
#     def setUserAsLogged(self, user):
#         self['user_key'] = str(user.key())
# 
#     def setUserAsLoggedByKey(self, key):
#         self['user_key'] = key
# 
# Path: lib/registry.py
# class Registry(dict):
#     def set(self, key, value):
#         self[key] = value
#     def get(self, key):
#         if self.has_key(key):
#             return self[key]
#         else:
#             return False


from modules.user.model.session import UserSession
from google.appengine.ext import webapp
from lib.registry import Registry

#decorator
def logged(f):
    def _inner(*args, **kwargs):
        if not UserSession().isLogged():
            raise BaseException('You are not authorized')
        return f(*args, **kwargs)

    return _inner

#decorator
def guest_only(f):
    def _inner(*args, **kwargs):
        if UserSession().isLogged():
            raise BaseException('You are not authorized')

# Path: modules/user/model/session.py
# class UserSession(AbstractSession):
#     namespace = 'user'
# 
#     def isLogged(self):
#         if 'user_key' in self:
#             return True
#         else:
#             return False
# 
#     def getUser(self):
#         if 'user_key' in self:
#             user = User.get(self['user_key'])
#             if not user:
#                 raise BaseException('User with key %s not found' % (self['user_key']))
#             return user
#         return False
# 
#     def setUserAsLogged(self, user):
#         self['user_key'] = str(user.key())
# 
#     def setUserAsLoggedByKey(self, key):
#         self['user_key'] = key
# 
# Path: lib/registry.py
# class Registry(dict):
#     def set(self, key, value):
#         self[key] = value
#     def get(self, key):
#         if self.has_key(key):
#             return self[key]
#         else:
#             return False


# Path: modules/core/model/app.py
from modules.user.model.session import UserSession
from google.appengine.ext import webapp
from lib.registry import Registry


#decorator
def logged(f):
    def _inner(*args, **kwargs):
        if not UserSession().isLogged():
            raise BaseException('You are not authorized')
        return f(*args, **kwargs)

    return _inner

#decorator
def guest_only(f):
    def _inner(*args, **kwargs):
        if UserSession().isLogged():
            raise BaseException('You are not authorized')

        return f(*args, **kwargs)