server.py
---------
#!/usr/bin/env python
#coding: utf-8
__author__ = 'spouk'
#---------------------------------------------------------------------------
# global imports
#---------------------------------------------------------------------------
from bottle import Bottle, TEMPLATE_PATH, request
from jinja2 import Environment, FileSystemLoader
from spouk_bottle_csrf import CSRF
#---------------------------------------------------------------------------
# set variables.../app/other stuff
#---------------------------------------------------------------------------
CSRF_SALT = 'somesalforcsrf'
TEMPLATE_PATH.append('template/')
env = Environment(loader=FileSystemLoader(TEMPLATE_PATH))
csrf = CSRF(csrf_salt=CSRF_SALT)
app=Bottle()
app.install(csrf)
#---------------------------------------------------------------------------
# definintion render, inject some map links variables
#---------------------------------------------------------------------------
def jinja(page, *args, **kwargs):
kwargs.update(dict(url_for=app.get_url))
kwargs.update(dict(csrf_html=app.csrf.csrf_html))
kwargs.update(dict(request=request))
kwargs.update(dict(app=app))
tpl = env.get_template(page)
return tpl.render(*args, **kwargs)
#---------------------------------------------------------------------------
# routing map
#---------------------------------------------------------------------------
@app.get('/')
def root():
return jinja('index.html')
@app.post('/', name="root")
def root_post():
# check validate tokens
print request.forms.get('csrf_token', None) == app.csrf.csrf_token_last and "Form and csrf token validate" or "Invalid csrf token"
return jinja('index.html')
app.run(host='localhost',port=3500, debug=True,reloader=True)
index.html
----------
<html>
<head>
<meta charset="utf-8" />
<meta content="{{app.csrf.csrf_token}}" name="csrf_token">
</head>
<body>
<h3> User form </h3>
<hr/>
<form method="post" action="{{ url_for('root')}}">
{{ csrf_html() }}
Username: <input type="text" name="username" >
Password: <input type="password" name="password">
<input type="submit" name="sender" value="Login">
</form>
<hr/>
{% if request.method == "POST" %}
<h3> Result validate form </h3>
<br/>
<p> Validate result: {{app.csrf.csrf_last == request.form.get('csrf_token',None)}}
{% endif %}
</body>
</html>
---
Copyleft [x] 2015, Spouk
Metadata
Release files for spouk-bottle-csrf 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spouk-bottle-csrf-0.0.2.tar.gz | 3.5 kB | Without provenance | Details for spouk-bottle-csrf-0.0.2.tar.gz |
Release files / spouk-bottle-csrf-0.0.2.tar.gz
| Download URL | spouk-bottle-csrf-0.0.2.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3483755fff264ab0e7fdb316cea22746f96bfab19666410cffe6a304fa9b3bd2
|
|
BLAKE2b-256 checksum How to use checksums |
cedb6398f962a44f6cb2a5d9132f90e9825587804a021ee70b2ce9f9082d2c7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for spouk-bottle-csrf 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.