예제 #1
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()
예제 #2
0
        if '_username' in request.params and '_password' in request.params:
            users = server.usermodel.Users(self.db_connection)
            user = users.login(request.params['_username'], request.params['_password'])
            if user:
                request.session['user'] = user  # save user to session
                return response.send_redirect("/?message=Successfully logged in as <i>{}</i>.".format(request.params['_username']))
            else:
                return response.send_template('login.tmpl',{'message':'Wrong username or password. Try again.'})
        # send login form
        return response.send_template('login.tmpl',{})


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_app(UsermanagementApp(db_connection=db))
    s.add_app(StaticApp(prefix='static', path='static'))

    s.add_app(MiniTwitterApp('data', db_connection=db))

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