##// END OF EJS Templates
Merged with BB
Merged with BB

File last commit:

r95:b1c17a3a default
r162:22721163 merge default
Show More
utils.py
64 lines | 1.6 KiB | text/x-python | PythonLexer
Ilyas
Added django-simple-capthca support...
r78 """
This module contains helper functions and helper classes.
"""
wnc_21
Added captcha support
r95
neko259
Fixed captcha design. Added setting to enable or disable captcha. This refs #39
r81 from neboard import settings
wnc_21
Added captcha support
r95 import time
Ilyas
Added django-simple-capthca support...
r78
wnc_21
Added captcha support
r95 KEY_CAPTCHA_FAILS = 'key_captcha_fails'
KEY_CAPTCHA_DELAY_TIME = 'key_captcha_delay_time'
KEY_CAPTCHA_LAST_ACTIVITY = 'key_captcha_last_activity'
def need_include_captcha(request):
Ilyas
Added django-simple-capthca support...
r78 """
Check if request is made by a user.
It contains rules which check for bots.
"""
wnc_21
Added captcha support
r95 if not settings.ENABLE_CAPTCHA:
return False
enable_captcha = False
#newcomer
if KEY_CAPTCHA_LAST_ACTIVITY not in request.session:
return settings.ENABLE_CAPTCHA
last_activity = request.session[KEY_CAPTCHA_LAST_ACTIVITY]
current_delay = int(time.time()) - last_activity
delay_time = (request.session[KEY_CAPTCHA_DELAY_TIME]
if KEY_CAPTCHA_DELAY_TIME in request.session
else settings.CAPTCHA_DEFAULT_SAFE_TIME)
if current_delay < delay_time:
enable_captcha = True
print 'ENABLING' + str(enable_captcha)
return enable_captcha
def update_captcha_access(request, passed):
"""
Update captcha fields.
It will reduce delay time if user passed captcha verification and
it will increase it otherwise.
"""
session = request.session
delay_time = (request.session[KEY_CAPTCHA_DELAY_TIME]
if KEY_CAPTCHA_DELAY_TIME in request.session
else settings.CAPTCHA_DEFAULT_SAFE_TIME)
print "DELAY TIME = " + str(delay_time)
if passed:
delay_time -= 2 if delay_time >= 7 else 5
else:
delay_time += 10
session[KEY_CAPTCHA_LAST_ACTIVITY] = int(time.time())
session[KEY_CAPTCHA_DELAY_TIME] = delay_time