Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Noah Brackenbury
erp5
Commits
ccb885b0
Commit
ccb885b0
authored
May 18, 2011
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use proper Cache Plugin API. Use sessions (which can be distributed with
proper cache plugin) rather than local dict.
parent
89986851
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
24 deletions
+18
-24
product/ERP5Form/CaptchaField.py
product/ERP5Form/CaptchaField.py
+16
-23
product/ERP5Type/Tool/SessionTool.py
product/ERP5Type/Tool/SessionTool.py
+2
-1
No files found.
product/ERP5Form/CaptchaField.py
View file @
ccb885b0
...
@@ -144,27 +144,20 @@ class CaptchaWidget(Widget.TextWidget):
...
@@ -144,27 +144,20 @@ class CaptchaWidget(Widget.TextWidget):
A widget that displays a Captcha.
A widget that displays a Captcha.
"""
"""
def
__init__
(
self
):
def
add_captcha
(
self
,
portal_sessions
,
key
,
value
):
# Associate a captcha key and (the right answer, the generation date)
session
=
portal_sessions
[
key
]
self
.
__captcha_cache
=
{}
if
session
.
has_key
(
key
):
def
add_captcha
(
self
,
key
,
value
):
# First, cleanup the cache
cleanup_time
=
time
.
time
()
-
3600
for
item
in
self
.
__captcha_cache
.
items
():
if
item
[
1
][
1
]
<
cleanup_time
:
del
(
self
.
__captcha_cache
[
item
[
0
]])
# Then add the value if needed
if
self
.
__captcha_cache
.
has_key
(
key
):
return
False
return
False
se
lf
.
__captcha_cache
[
key
]
=
(
str
(
value
),
time
.
time
())
se
ssion
[
key
]
=
value
return
True
return
True
def
validate_answer
(
self
,
key
,
value
):
def
validate_answer
(
self
,
portal_sessions
,
key
,
value
):
if
not
(
self
.
__captcha_cache
.
has_key
(
key
)):
session
=
portal_sessions
[
key
]
if
not
(
session
.
has_key
(
key
)):
return
False
return
False
result
=
(
self
.
__captcha_cache
[
key
][
0
]
==
value
)
result
=
(
session
[
key
]
==
value
)
del
(
self
.
__captcha_cache
[
key
])
# Forbid several use of the same captcha.
# Forbid several use of the same captcha.
del
(
session
[
key
])
return
result
return
result
property_names
=
Widget
.
Widget
.
property_names
+
[
'captcha_type'
]
property_names
=
Widget
.
Widget
.
property_names
+
[
'captcha_type'
]
...
@@ -185,11 +178,11 @@ class CaptchaWidget(Widget.TextWidget):
...
@@ -185,11 +178,11 @@ class CaptchaWidget(Widget.TextWidget):
"""
"""
captcha_key
=
None
captcha_key
=
None
captcha_field
=
None
captcha_field
=
None
captcha_type
=
field
.
get_value
(
"captcha_type"
)
captcha_type
=
field
.
get_value
(
"captcha_type"
)
provider
=
CaptchaProviderFactory
.
getProvider
(
captcha_type
)
provider
=
CaptchaProviderFactory
.
getProvider
(
captcha_type
)
(
captcha_key
,
captcha_answer
)
=
provider
.
generate
(
field
)
(
captcha_key
,
captcha_answer
)
=
provider
.
generate
(
field
)
while
not
(
self
.
add_captcha
(
md5
.
new
(
captcha_key
).
hexdigest
(),
captcha_answer
)):
portal_sessions
=
field
.
getPortalObject
().
portal_sessions
while
not
(
self
.
add_captcha
(
portal_sessions
,
md5
.
new
(
captcha_key
).
hexdigest
(),
captcha_answer
)):
(
captcha_key
,
captcha_answer
)
=
provider
.
generate
(
field
)
(
captcha_key
,
captcha_answer
)
=
provider
.
generate
(
field
)
captcha_field
=
provider
.
getHTML
(
field
,
captcha_key
)
captcha_field
=
provider
.
getHTML
(
field
,
captcha_key
)
...
@@ -222,8 +215,8 @@ class CaptchaValidator(Validator.Validator):
...
@@ -222,8 +215,8 @@ class CaptchaValidator(Validator.Validator):
def
validate
(
self
,
field
,
key
,
REQUEST
):
def
validate
(
self
,
field
,
key
,
REQUEST
):
value
=
REQUEST
.
get
(
key
,
None
)
value
=
REQUEST
.
get
(
key
,
None
)
cache_key
=
REQUEST
.
get
(
"__captcha_"
+
key
+
"__"
)
cache_key
=
REQUEST
.
get
(
"__captcha_"
+
key
+
"__"
)
portal_sessions
=
field
.
getPortalObject
().
portal_sessions
if
not
(
CaptchaWidgetInstance
.
validate_answer
(
cache_key
,
value
)):
if
not
(
CaptchaWidgetInstance
.
validate_answer
(
portal_sessions
,
cache_key
,
value
)):
self
.
raise_error
(
'wrong_captcha'
,
field
)
self
.
raise_error
(
'wrong_captcha'
,
field
)
return
value
return
value
...
...
product/ERP5Type/Tool/SessionTool.py
View file @
ccb885b0
...
@@ -215,7 +215,8 @@ class SessionTool(BaseTool):
...
@@ -215,7 +215,8 @@ class SessionTool(BaseTool):
session
.
_updateSessionId
(
session_id
)
session
.
_updateSessionId
(
session_id
)
if
session_duration
is
None
:
if
session_duration
is
None
:
# set session duration (this is used from backend storage machinery for expire purposes)
# set session duration (this is used from backend storage machinery for expire purposes)
session_duration
=
self
.
portal_caches
[
SESSION_CACHE_FACTORY
].
objectValues
()[
0
].
cache_duration
cache_plugin
=
self
.
portal_caches
[
SESSION_CACHE_FACTORY
].
objectValues
()[
0
]
session_duration
=
cache_plugin
.
getCacheDuration
()
session
.
_updateSessionDuration
(
session_duration
)
session
.
_updateSessionDuration
(
session_duration
)
storage_plugin
.
set
(
session_id
,
SESSION_SCOPE
,
session
,
session_duration
)
storage_plugin
.
set
(
session_id
,
SESSION_SCOPE
,
session
,
session_duration
)
else
:
else
:
...
...
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