{ "info": { "author": "Spouk", "author_email": "spouk@spouk.ru", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "csrf support for bottle\n server.py\n ---------\n #!/usr/bin/env python\n #coding: utf-8\n __author__ = 'spouk'\n\n #---------------------------------------------------------------------------\n # global imports\n #---------------------------------------------------------------------------\n\n from bottle import Bottle, TEMPLATE_PATH, request\n from jinja2 import Environment, FileSystemLoader\n from spouk_bottle_csrf import CSRF\n\n #---------------------------------------------------------------------------\n # set variables.../app/other stuff\n #---------------------------------------------------------------------------\n\n CSRF_SALT = 'somesalforcsrf'\n TEMPLATE_PATH.append('template/')\n env = Environment(loader=FileSystemLoader(TEMPLATE_PATH))\n csrf = CSRF(csrf_salt=CSRF_SALT)\n\n app=Bottle()\n app.install(csrf)\n\n\n #---------------------------------------------------------------------------\n # definintion render, inject some map links variables\n #---------------------------------------------------------------------------\n\n def jinja(page, *args, **kwargs):\n\n kwargs.update(dict(url_for=app.get_url))\n kwargs.update(dict(csrf_html=app.csrf.csrf_html))\n kwargs.update(dict(request=request))\n kwargs.update(dict(app=app))\n tpl = env.get_template(page)\n return tpl.render(*args, **kwargs)\n\n #---------------------------------------------------------------------------\n # routing map\n #---------------------------------------------------------------------------\n\n @app.get('/')\n def root():\n return jinja('index.html')\n\n @app.post('/', name=\"root\")\n def root_post():\n # check validate tokens\n print request.forms.get('csrf_token', None) == app.csrf.csrf_token_last and \"Form and csrf token validate\" or \"Invalid csrf token\"\n return jinja('index.html')\n\n app.run(host='localhost',port=3500, debug=True,reloader=True)\n\n\n index.html\n ----------\n \n \n \n \n \n \n

User form

\n
\n
\n {{ csrf_html() }}\n Username: \n Password: \n \n
\n
\n {% if request.method == \"POST\" %}\n

Result validate form

\n
\n

Validate result: {{app.csrf.csrf_last == request.form.get('csrf_token',None)}}\n\n {% endif %}\n\n \n \n\n\n\n ---\n Copyleft [x] 2015, Spouk", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://spouk.ru", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "spouk-bottle-csrf", "package_url": "https://pypi.org/project/spouk-bottle-csrf/", "platform": "any", "project_url": "https://pypi.org/project/spouk-bottle-csrf/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://spouk.ru" }, "release_url": "https://pypi.org/project/spouk-bottle-csrf/0.0.2/", "requires_dist": null, "requires_python": null, "summary": "csrf plugin for bottle", "version": "0.0.2" }, "last_serial": 1864934, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "6541f2993098324a6468bbb241421f4b", "sha256": "08a46315f35f219cd912c5d4c930ac832a7799d81d6e0c9d67f09537b4339a40" }, "downloads": -1, "filename": "spouk-bottle-csrf-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6541f2993098324a6468bbb241421f4b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3835, "upload_time": "2015-12-14T17:18:34", "url": "https://files.pythonhosted.org/packages/6a/12/8fccdc85b6afd2817b8df5e7f5407f666d7e81a7cd5d1d0b8d8fbe91c26f/spouk-bottle-csrf-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "bf4d2be51b71368578fd4d87b1ea6e8a", "sha256": "3483755fff264ab0e7fdb316cea22746f96bfab19666410cffe6a304fa9b3bd2" }, "downloads": -1, "filename": "spouk-bottle-csrf-0.0.2.tar.gz", "has_sig": false, "md5_digest": "bf4d2be51b71368578fd4d87b1ea6e8a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3518, "upload_time": "2015-12-16T11:58:42", "url": "https://files.pythonhosted.org/packages/ce/db/6398f962a44f6cb2a5d9132f90e9825587804a021ee70b2ce9f9082d2c7f/spouk-bottle-csrf-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bf4d2be51b71368578fd4d87b1ea6e8a", "sha256": "3483755fff264ab0e7fdb316cea22746f96bfab19666410cffe6a304fa9b3bd2" }, "downloads": -1, "filename": "spouk-bottle-csrf-0.0.2.tar.gz", "has_sig": false, "md5_digest": "bf4d2be51b71368578fd4d87b1ea6e8a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3518, "upload_time": "2015-12-16T11:58:42", "url": "https://files.pythonhosted.org/packages/ce/db/6398f962a44f6cb2a5d9132f90e9825587804a021ee70b2ce9f9082d2c7f/spouk-bottle-csrf-0.0.2.tar.gz" } ] }