Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
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
nexedi
converse.js
Commits
559fa4b7
Commit
559fa4b7
authored
Jul 23, 2012
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add simple honeypot based spam protection (issue #82)
parent
d830dc2c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
1 deletion
+32
-1
weblate/html/translate.html
weblate/html/translate.html
+1
-0
weblate/media/js/loader.js
weblate/media/js/loader.js
+1
-0
weblate/trans/forms.py
weblate/trans/forms.py
+13
-0
weblate/trans/views.py
weblate/trans/views.py
+17
-1
No files found.
weblate/html/translate.html
View file @
559fa4b7
...
...
@@ -30,6 +30,7 @@
<form
action=
"{{ unit.translation.get_translate_url }}"
method=
"post"
>
{% csrf_token %}
{% if antispam %}
<div
id=
"s_content"
>
{{ antispam }}
</div>
{% endif %}
<input
type=
"hidden"
name=
"type"
value=
"{{ type }}"
/>
<input
type=
"hidden"
name=
"pos"
value=
"{{ unit.position }}"
/>
<input
type=
"hidden"
name=
"q"
value=
"{{ search_query }}"
/>
...
...
weblate/media/js/loader.js
View file @
559fa4b7
...
...
@@ -283,4 +283,5 @@ $(function() {
$
(
"
form.autosubmit select
"
).
change
(
function
()
{
$
(
"
form.autosubmit
"
).
submit
();
});
$
(
'
div#s_content
'
).
hide
();
});
weblate/trans/forms.py
View file @
559fa4b7
...
...
@@ -100,6 +100,19 @@ class TranslationForm(forms.Form):
target
=
PluralField
(
required
=
False
)
fuzzy
=
forms
.
BooleanField
(
label
=
pgettext_lazy
(
'Checkbox for marking translation fuzzy'
,
'Fuzzy'
),
required
=
False
)
class
AntispamForm
(
forms
.
Form
):
'''
Honeypot based spam protection form.
'''
content
=
forms
.
CharField
()
def
clean
(
self
):
'''
Check if content is empty.
'''
if
self
.
cleaned_data
[
'content'
]
!=
''
:
raise
ValidationError
(
'Invalid value'
)
class
SimpleUploadForm
(
forms
.
Form
):
file
=
forms
.
FileField
(
label
=
_
(
'File'
))
...
...
weblate/trans/views.py
View file @
559fa4b7
...
...
@@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse
from
weblate.trans.models
import
Project
,
SubProject
,
Translation
,
Unit
,
Suggestion
,
Check
,
Dictionary
,
Change
from
weblate.lang.models
import
Language
from
weblate.trans.checks
import
CHECKS
from
weblate.trans.forms
import
TranslationForm
,
UploadForm
,
SimpleUploadForm
,
ExtraUploadForm
,
SearchForm
,
MergeForm
,
AutoForm
,
WordForm
,
DictUploadForm
,
ReviewForm
,
LetterForm
from
weblate.trans.forms
import
TranslationForm
,
UploadForm
,
SimpleUploadForm
,
ExtraUploadForm
,
SearchForm
,
MergeForm
,
AutoForm
,
WordForm
,
DictUploadForm
,
ReviewForm
,
LetterForm
,
AntispamForm
from
weblate.trans.util
import
join_plural
from
weblate.accounts.models
import
Profile
...
...
@@ -660,8 +660,10 @@ def translate(request, project, subproject, lang):
if
request
.
user
.
is_authenticated
():
profile
=
request
.
user
.
get_profile
()
antispam
=
None
else
:
profile
=
None
antispam
=
AntispamForm
()
secondary
=
None
unit
=
None
...
...
@@ -670,6 +672,19 @@ def translate(request, project, subproject, lang):
# Any form submitted?
if
request
.
method
==
'POST'
:
# Antispam protection
if
not
request
.
user
.
is_authenticated
():
antispam
=
AntispamForm
(
request
.
POST
)
if
not
antispam
.
is_valid
():
# Silently redirect to next entry
return
HttpResponseRedirect
(
'%s?type=%s&pos=%d%s'
%
(
obj
.
get_translate_url
(),
rqtype
,
pos
,
search_url
))
form
=
TranslationForm
(
request
.
POST
)
if
form
.
is_valid
()
and
not
obj
.
subproject
.
locked
:
# Check whether translation is not outdated
...
...
@@ -929,6 +944,7 @@ def translate(request, project, subproject, lang):
'filter_count'
:
filter_count
,
'filter_pos'
:
filter_count
+
1
-
units
.
count
(),
'form'
:
form
,
'antispam'
:
antispam
,
'target_language'
:
obj
.
language
.
code
,
'secondary'
:
secondary
,
'search_query'
:
search_query
,
...
...
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