Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
Respect My Net
Commits
48adae3f
Commit
48adae3f
authored
Jul 14, 2011
by
stef
Browse files
[enh] error-handling around gets for activation/confirmation/approval
parent
7415eae6
Changes
1
Hide whitespace changes
Inline
Side-by-side
bt/views.py
View file @
48adae3f
...
@@ -44,7 +44,10 @@ def sanitizeHtml(value, base_url=None):
...
@@ -44,7 +44,10 @@ def sanitizeHtml(value, base_url=None):
return
soup
.
renderContents
().
decode
(
'utf8'
)
return
soup
.
renderContents
().
decode
(
'utf8'
)
def
activate
(
request
):
def
activate
(
request
):
v
=
Violation
.
objects
.
get
(
activationid
=
request
.
GET
.
get
(
'key'
,
'asdf'
))
try
:
v
=
Violation
.
objects
.
get
(
activationid
=
request
.
GET
.
get
(
'key'
,
'asdf'
))
except
:
return
HttpResponse
(
"Thank you, this has been already activated"
)
if
v
:
if
v
:
actid
=
hashlib
.
sha1
(
''
.
join
([
chr
(
randint
(
32
,
122
))
for
x
in
range
(
12
)])).
hexdigest
()
actid
=
hashlib
.
sha1
(
''
.
join
([
chr
(
randint
(
32
,
122
))
for
x
in
range
(
12
)])).
hexdigest
()
to
=
[
x
.
email
for
x
in
User
.
objects
.
filter
(
groups__name
=
'moderator'
)]
to
=
[
x
.
email
for
x
in
User
.
objects
.
filter
(
groups__name
=
'moderator'
)]
...
@@ -61,7 +64,10 @@ def activate(request):
...
@@ -61,7 +64,10 @@ def activate(request):
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
def
moderate
(
request
):
def
moderate
(
request
):
v
=
Violation
.
objects
.
get
(
activationid
=
request
.
GET
.
get
(
'key'
,
'asdf'
))
try
:
v
=
Violation
.
objects
.
get
(
activationid
=
request
.
GET
.
get
(
'key'
,
'asdf'
))
except
:
return
HttpResponse
(
"Thank you, this has been already activated"
)
if
not
v
:
if
not
v
:
messages
.
add_message
(
request
,
messages
.
INFO
,
_
(
'No such key'
))
messages
.
add_message
(
request
,
messages
.
INFO
,
_
(
'No such key'
))
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
return
HttpResponseRedirect
(
'/'
)
# Redirect after POST
...
@@ -85,7 +91,10 @@ def confirm(request, id, name=None):
...
@@ -85,7 +91,10 @@ def confirm(request, id, name=None):
if
name
:
if
name
:
if
Confirmation
.
objects
.
filter
(
email
=
name
,
violation
=
id
).
count
()
==
0
:
if
Confirmation
.
objects
.
filter
(
email
=
name
,
violation
=
id
).
count
()
==
0
:
actid
=
sendverifymail
(
'confirm/'
,
name
)
actid
=
sendverifymail
(
'confirm/'
,
name
)
c
=
Confirmation
(
key
=
actid
,
email
=
name
,
violation
=
Violation
.
objects
.
get
(
pk
=
id
))
try
:
c
=
Confirmation
(
key
=
actid
,
email
=
name
,
violation
=
Violation
.
objects
.
get
(
pk
=
id
))
except
:
return
HttpResponse
(
"Thank you, this has been already confirmed"
)
c
.
save
()
c
.
save
()
return
HttpResponse
(
'<div class="confirm_thanks">Thank you for your confirmation</div>'
)
return
HttpResponse
(
'<div class="confirm_thanks">Thank you for your confirmation</div>'
)
c
=
Confirmation
.
objects
.
get
(
key
=
id
)
c
=
Confirmation
.
objects
.
get
(
key
=
id
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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