# -*- coding: utf-8 -*-
import logging

from pylons import request, response, session, tmpl_context as c
from pylons.controllers.util import abort, redirect_to

from {{package}}.lib.base import BaseController, render

log = logging.getLogger(__name__)

from {{package}}.model import *
from {{package}}.lib import auth
from {{package}}.lib.decorators import authorize
from {{package}}.lib.auth.permissions import SignedIn

class DemoController(BaseController):

    # Need to protect an entire controller?
    # Decorating __before__ protects all actions
    
    # @authorize(SignedIn())
    def __before__(self):
        pass
    

    def index(self):
        c.users = Session.query(User).all()
        c.groups = Session.query(Group).all()
        c.permissions = Session.query(Permission).all()
        c.title = 'Public'
        return render('test.mak')
    

    # Need to protect just a single action?
    # Do it like this ....
    @authorize(SignedIn())
    def privindex(self):
        c.users = Session.query(User).all()
        c.groups = Session.query(Group).all()
        c.permissions = Session.query(Permission).all()
        # Use this for obviousness
        # c.user = auth.get_user()
        # or this for directness
        c.user = request.environ['AUTH_USER']
        c.title = 'Private'
        return render('test.mak')
    
