##// END OF EJS Templates
Added tag 2.2.4 for changeset 1b52ba60f17f
Added tag 2.2.4 for changeset 1b52ba60f17f

File last commit:

r903:0de4b802 default
r940:9c5260c9 default
Show More
utils.py
42 lines | 1.1 KiB | text/x-python | PythonLexer
"""
This module contains helper functions and helper classes.
"""
import time
import hmac
from django.utils import timezone
from neboard import settings
KEY_CAPTCHA_FAILS = 'key_captcha_fails'
KEY_CAPTCHA_DELAY_TIME = 'key_captcha_delay_time'
KEY_CAPTCHA_LAST_ACTIVITY = 'key_captcha_last_activity'
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[-1].strip()
else:
ip = request.META.get('REMOTE_ADDR')
return ip
def datetime_to_epoch(datetime):
return int(time.mktime(timezone.localtime(
datetime,timezone.get_current_timezone()).timetuple())
* 1000000 + datetime.microsecond)
def get_websocket_token(user_id='', timestamp=''):
"""
Create token to validate information provided by new connection.
"""
sign = hmac.new(settings.CENTRIFUGE_PROJECT_SECRET.encode())
sign.update(settings.CENTRIFUGE_PROJECT_ID.encode())
sign.update(user_id.encode())
sign.update(timestamp.encode())
token = sign.hexdigest()
return token