Exemple #1
0
                                       'save action needs pagename')

            try:
                wikitext = request.params['wikitext']
            except KeyError:
                # no text given: error
                return self.send_error(response, 'No text given.',
                                       'save action needs text.')

            f = open("data/" + pagename, "w", encoding='utf-8', newline='')
            f.write(wikitext)
            f.close()

            response.send_redirect("/show/" + pagename)


if __name__ == '__main__':
    s = webserver.Webserver()
    s.set_templating(
        "pystache"
    )  # use good old string.format for templating (like we used to in the past weeks)
    s.set_templating_path("templates/wiki")  # where are the templates?
    s.add_app(WikiApp())
    s.add_app(StaticApp(prefix='static', path='static'))
    s.add_middleware(
        SessionMiddleware()
    )  # let's have sessions (not really needed for this version but if you add auth...)
    s.add_middleware(
        AuthMiddleware('login.mustache'))  #Authentication middleware
    s.serve()
Exemple #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()
Exemple #3
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()