示例#1
0
            newmsg = ''

        (found, msg) = g.guess(guess)
        if found:  # destroy session
            # new session and number will be generated next time
            request.session.renew()
            count = 1
        else:
            # pass sessid id to hidden input field
            count = g.count + 1

        d = {'msg': msg, 'newmsg': newmsg, 'cnt': count,
             'variant': 'Session per Cookie', 'hidden': ''}
        response.send_template('show.tmpl', d)


if __name__ == '__main__':
    s = Webserver()
    s.set_templating("jinja2")
    s.set_templating_path("templates.jinja2")
    s.add_app(WelcomeApp())
    s.add_app(GlobalGuessApp(prefix='global/?'))
    s.add_app(CookieGuesserApp(prefix='cookies/?'))
    s.add_app(GetGuesserApp(prefix='get/?'))
    s.add_app(SessionGuesserApp(prefix='session/?'))
    s.add_app(StaticApp(prefix='', path='static'))
    s.add_middleware(SessionMiddleware())  # let's have sessions

    s.serve()

示例#2
0
            else:
                return response.send_template(
                    'login.tmpl',
                    {'message': 'Wrong username or password. Try again.'})
        # send login form
        return response.send_template(
            'login.tmpl', {'user': server.usermodel.AnonymousUser()})


if __name__ == '__main__':

    db = sqlite.connect('minitwitter.sqlite')  # use sqlite db
    db.row_factory = sqlite.Row  # fetch rows as Row objects (easier to access)

    s = Webserver()
    s.set_templating("jinja2")
    s.set_templating_path("templates.jinja2")

    s.add_middleware(SessionMiddleware())
    s.add_middleware(CsrfMiddleware())

    s.add_app(UsermanagementApp(db_connection=db)
              )  # Sub-App: create, change, delete users. (code in server/apps)
    s.add_app(StaticApp(prefix='static',
                        path='static'))  # deliver static files

    s.add_app(MiniTwitterApp('data', db_connection=db))  # the twitter app

    log(0, "Server running.")
    s.serve()
示例#3
0
    def logout(self, request, response, pathmatch):
        if request.session:
            request.session.destroy()
        response.send_redirect("/")

    def login(self, request, response, pathmatch):
        request.require_login()
        response.send_redirect("/")


if __name__ == '__main__':

    db = sqlite.connect('minitwitter.sqlite')
    db.row_factory = sqlite.Row

    s = Webserver()
    s.set_templating("pystache")
    s.set_templating_path("templates.mustache")

    s.add_middleware(SessionMiddleware())
    s.add_middleware(
        AuthMiddleware(login_template='login.tmpl', db_connection=db))

    s.add_app(UsermanagementApp(db_connection=db))
    s.add_app(StaticApp(prefix='static', path='static'))

    s.add_app(MiniTwitterApp('data'))

    log(0, "Server running.")
    s.serve()