-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
32 lines (26 loc) · 1.11 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-"""
import json
from django.conf import settings
from django.http import HttpResponse
if settings.HAS_XMPP:
from conversejs.models import XMPPAccount
from conversejs.boshclient import BOSHClient
from utils import session_get_credentials, session_put_credentials
else:
from .models import XMPPAccount
def bosh_prebind(request):
print '--- bosh_prebind'
jid, sid, rid = session_get_credentials(request)
if jid and sid and rid:
rid += 1
request.session['rid'] = rid+1
# print 'existent credentials: ', jid, sid, rid
else:
xmpp_account = XMPPAccount.objects.get(user=request.user.pk)
if settings.HAS_XMPP:
bosh = BOSHClient(xmpp_account.jid, xmpp_account.password,
settings.CONVERSEJS_BOSH_SERVICE_URL)
jid, sid, rid = bosh.get_credentials()
session_put_credentials(request, jid, sid, rid)
# print 'new credentials: ', jid, sid, rid
return HttpResponse(json.dumps({'jid': jid, 'sid': sid, 'rid': rid}), content_type='application/json')