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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
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
Hide 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
...
...
@@ -143,28 +143,21 @@ class CaptchaWidget(Widget.TextWidget):
"""
A widget that displays a Captcha.
"""
def
__init__
(
self
):
# Associate a captcha key and (the right answer, the generation date)
self
.
__captcha_cache
=
{}
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
):
def
add_captcha
(
self
,
portal_sessions
,
key
,
value
):
session
=
portal_sessions
[
key
]
if
session
.
has_key
(
key
):
return
False
self
.
__captcha_cache
[
key
]
=
(
str
(
value
),
time
.
time
())
return
True
def
validate_answer
(
self
,
key
,
value
):
if
not
(
self
.
__captcha_cache
.
has_key
(
key
)):
session
[
key
]
=
value
return
True
def
validate_answer
(
self
,
portal_sessions
,
key
,
value
):
session
=
portal_sessions
[
key
]
if
not
(
session
.
has_key
(
key
)):
return
False
result
=
(
self
.
__captcha_cache
[
key
][
0
]
==
value
)
del
(
self
.
__captcha_cache
[
key
])
# Forbid several use of the same captcha.
result
=
(
session
[
key
]
==
value
)
# Forbid several use of the same captcha.
del
(
session
[
key
])
return
result
property_names
=
Widget
.
Widget
.
property_names
+
[
'captcha_type'
]
...
...
@@ -185,11 +178,11 @@ class CaptchaWidget(Widget.TextWidget):
"""
captcha_key
=
None
captcha_field
=
None
captcha_type
=
field
.
get_value
(
"captcha_type"
)
provider
=
CaptchaProviderFactory
.
getProvider
(
captcha_type
)
(
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_field
=
provider
.
getHTML
(
field
,
captcha_key
)
...
...
@@ -222,8 +215,8 @@ class CaptchaValidator(Validator.Validator):
def
validate
(
self
,
field
,
key
,
REQUEST
):
value
=
REQUEST
.
get
(
key
,
None
)
cache_key
=
REQUEST
.
get
(
"__captcha_"
+
key
+
"__"
)
if
not
(
CaptchaWidgetInstance
.
validate_answer
(
cache_key
,
value
)):
portal_sessions
=
field
.
getPortalObject
().
portal_sessions
if
not
(
CaptchaWidgetInstance
.
validate_answer
(
portal_sessions
,
cache_key
,
value
)):
self
.
raise_error
(
'wrong_captcha'
,
field
)
return
value
...
...
product/ERP5Type/Tool/SessionTool.py
View file @
ccb885b0
...
...
@@ -215,7 +215,8 @@ class SessionTool(BaseTool):
session
.
_updateSessionId
(
session_id
)
if
session_duration
is
None
:
# 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
)
storage_plugin
.
set
(
session_id
,
SESSION_SCOPE
,
session
,
session_duration
)
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