Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
46958eb0
Commit
46958eb0
authored
Sep 17, 2015
by
Paul Brown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add SecureForm for easier CSRF validation
parent
1975115a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletion
+27
-1
__init__.py
flask_admin/form/__init__.py
+27
-1
No files found.
flask_admin/form/__init__.py
View file @
46958eb0
from
wtforms
import
form
from
wtforms
import
form
,
__version__
as
wtforms_version
from
wtforms.fields.core
import
UnboundField
from
wtforms.fields.core
import
UnboundField
from
.fields
import
*
from
.fields
import
*
...
@@ -32,3 +32,29 @@ def recreate_field(unbound):
...
@@ -32,3 +32,29 @@ def recreate_field(unbound):
raise
ValueError
(
'recreate_field expects UnboundField instance,
%
s was passed.'
%
type
(
unbound
))
raise
ValueError
(
'recreate_field expects UnboundField instance,
%
s was passed.'
%
type
(
unbound
))
return
unbound
.
field_class
(
*
unbound
.
args
,
**
unbound
.
kwargs
)
return
unbound
.
field_class
(
*
unbound
.
args
,
**
unbound
.
kwargs
)
if
int
(
wtforms_version
[
0
])
>
1
:
# only WTForms 2+ has built-in CSRF functionality
from
os
import
urandom
from
flask
import
session
from
wtforms.csrf.session
import
SessionCSRF
class
SecureForm
(
BaseForm
):
"""
BaseForm with CSRF token generation and validation support.
Requires WTForms 2+
"""
class
Meta
:
csrf
=
True
csrf_class
=
SessionCSRF
csrf_secret
=
urandom
(
24
)
@
property
def
csrf_context
(
self
):
return
session
else
:
class
SecureForm
(
BaseForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
raise
Exception
(
"SecureForm requires WTForms 2+"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment