Beispiel #1
0
def create_auth_manifest(**kwargs):
    """
    Creates a basic authentication manifest for logging in, logging out and
    registering new accounts.
    """
    class AuthProgram(Program):
        pre_input_middleware = [AuthenticationMiddleware]

    def register(username, password, password2):
        """
        Decorated version of basic_register with a callback added.
        """
        result = basic_register(username, password, password2)
        callback = kwargs.get('post_register_callback', None)
        if callback:
            user = User.objects.get(username=username)
            callback(user)
        return result

    return Manifest({
        'login': [
            AuthProgram(
                """
                Prints out the HTML form for logging in.
                """,
                name="Login (form)",
                input_middleware=[NotAuthenticatedOrRedirect('/')],
                view=BasicView(
                    html=jinja_template('login.html'),
                ),
            ),
            AuthProgram(
                """
                Matches up the username/password against the database, and adds the auth cookies.
                """,
                name="Login (post)",
                input_middleware=[NotAuthenticatedOrDie],
                controllers=['http-post', 'cmd'],
                model=[create_session, {'username': '******', 'session_key': 'XXXXXXXXXXXXXXX'}],
                view=BasicView(
                    persist=lambda m: {'giotto_session': m['session_key']},
                    html=lambda m: Redirection('/'),
                ),
            ),
        ],
        'logout': AuthProgram(
            """
            Send the user here to log them out. Removes their cookies and deletes the auth session.
            """,
            name="Logout",
            view=BasicView(
                html=Redirection('/'),
            ),
            output_middleware=[LogoutMiddleware],
        ),
        'register': [
            AuthProgram(
                """
                This program returns the HTML page with the form for registering a new account.
                HTTP-get only.
                """,
                name="Register (form)",
                input_middleware=[NotAuthenticatedOrRedirect('/')],
                view=BasicView(
                    html=jinja_template('register.html'),
                ),
            ),
            AuthProgram(
                """
                When you POST the register form, this program handles creating the new user, then redirecting you to '/'
                """,
                name="Register (post)",
                controllers=['http-post'],
                model=[register],
                view=BasicView(
                    persist=lambda m: {'giotto_session': m['session_key']},
                    html=lambda m: Redirection('/'),
                ),
            ),
        ],
    })
Beispiel #2
0
    # not committed because it contains secret API keys
    functional_test()

class AuthenticationRequiredProgram(Program):
    pre_input_middleware = [AuthenticationMiddleware, AuthenticatedOrDie]

class AuthenticationProgram(Program):
    pre_input_middleware = [AuthenticationMiddleware]

manifest = Manifest({
    '': '/landing',
    'landing': AuthenticationProgram(
        input_middleware=[NotAuthenticatedOrRedirect('/ui/dashboard')],
        model=[server.home],
        view=BasicView(
            html=jinja_template('landing.html'),
        ),
    ),
    'apps': Manifest({
        'camera': Program(
            view=BasicView(
                html=jinja_template("camera.html"),
            ),
        ),
        'blog': Program(
            view=BasicView(
                html=jinja_template("blog.html"),
            ),
        ),
        'music': Program(
            view=BasicView(
Beispiel #3
0
     view=BasicView(
         html=lazy_jinja_template('html/blog_index.html'),
     ),
     output_middleware=[RenderLazytemplate]
 ),
 'blog': AuthProgram(
     model=[Blog.get, get_blog_mock()],
     view=BasicView(
         html=partial_jinja_template('html/blog.html'),
     ),
 ),
 'new': [
     AuthProgram(
         input_middleware=[AuthenticatedOrDie],
         view=BasicView(
             html=jinja_template('html/blog_form.html'),
         ),
     ),
     AuthProgram(
         input_middleware=[AuthenticatedOrDie],
         controllers = ('http-post', 'cmd'),
         model=[Blog.create, make_mock_blog()],
         view=BasicView(
             html=lambda m: Redirection("/blog/%s" % m.id),
         ),
     ),
 ],
 'edit': [
     AuthProgram(
         model=[Blog.get],
         view=BasicView(
Beispiel #4
0
from giotto.contrib.static.programs import StaticServe
from giotto.programs import Program, Manifest
from giotto.programs.management import management_manifest
from giotto.views import BasicView, jinja_template
from models import show_listings, CrawlResult, stats

manifest = Manifest({
    '':
    '/stats',
    'stats':
    Program(model=[stats],
            view=BasicView(html=jinja_template('landing.html'))),
    'api_docs':
    Program(view=BasicView(html=jinja_template('api.html'))),
    'listings':
    Program(model=[show_listings],
            view=BasicView(html=jinja_template("show_listings.html"))),
    'crawl':
    Program(
        controllers=['cmd'],
        model=[CrawlResult.do_crawl],
    ),
    'static':
    StaticServe('/static'),
    'mgt':
    management_manifest,
})
Beispiel #5
0
from giotto import get_config

from giotto.programs import GiottoProgram, ProgramManifest
from giotto.programs.management import management_manifest
from giotto.contrib.static.programs import StaticServe
from giotto.views import BasicView, jinja_template

from crawl import crawl
from models import Submission


def front():
    session = get_config("db_session")
    return session.query(Submission).filter(Submission.current_rank > 0).order_by("current_rank")


manifest = ProgramManifest(
    {
        "": GiottoProgram(
            model=[front],
            # cache=30,
            view=BasicView(html=jinja_template("better_front.html")),
        ),
        "about": GiottoProgram(view=BasicView(html=jinja_template("about.html"))),
        "crawl": GiottoProgram(controllers=["cmd"], model=[crawl], view=BasicView),
        "mgt": management_manifest,
        "static": StaticServe("/static/"),
    }
)
Beispiel #6
0
from giotto.programs.management import management_manifest
from giotto.views import BasicView, jinja_template
from giotto.contrib.static.programs import StaticServe, SingleStaticServe
from giotto.control import Redirection

from models import Album, Song, get_bucket_contents, add_all, add_album, reload_album
from mocks import mock_album, mock_songs, mock_venues, mock_venue, mock_song

from views import album2json

manifest = Manifest({
    '': Program(
        model=[Album.most_recent],
        cache=3600,
        view=BasicView(
            html=jinja_template('home.html'),
        ),
    ),
    'albums': Program(
        model=[Album.all, {'albums': [mock_album]}],
        cache=3600,
        view=BasicView(
            html=jinja_template('all_albums.html'),
        ),
    ),
    'album': Program(
        model=[Album.get, {'album': mock_album}],
        cache=3600,
        view=BasicView(
            html=jinja_template('album.html'),
            json=album2json,
Beispiel #7
0
from giotto.contrib.static.programs import StaticServe
from giotto.programs import Program, Manifest
from giotto.programs.management import management_manifest
from giotto.views import BasicView, jinja_template
from models import show_listings, CrawlResult, stats

manifest = Manifest({
    '': '/stats',
    'stats': Program(
        model=[stats],
        view=BasicView(
            html=jinja_template('landing.html')
        )
    ),
    'api_docs': Program(
        view=BasicView(
            html=jinja_template('api.html')
        )
    ),
    'listings': Program(
        model=[show_listings],
        view=BasicView(
            html=jinja_template("show_listings.html")
        )
    ),
    'crawl': Program(
        controllers=['cmd'],
        model=[CrawlResult.do_crawl],
    ),
    'static': StaticServe('/static'),
    'mgt': management_manifest,