from xmpp import Client from xmpp protocol import JID from django cont

 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
33
34
from xmpp import Client
from xmpp.protocol import JID
from django.contrib.auth.models import User
def xmpp_login(jid, password): #supose that jid already checked for email format
jid = JID(jid)
jid_str = "%s" % jid
client = Client(jid.getDomain(),debug=[])
con = client.connect()
if not con:
raise Exception('Cannot connect to jabber server')
auth=client.auth(jid.getNode(), password, resource=jid.getResource()) # resource =)
if not auth:
raise Exception('Cannot auth at jabber server')
try:
user = User.objects.get(username=jid)
except User.DoesNotExist:
user = User.objects.create_user(jid_str, jid_str, password) # user already is_authenticated()
user.save()
return user
from django.contrib.auth import authenticate
user = authenticate(username=jid_str, password=password)
if user is not None:
g if user.is_active:
return user
else:
raise Exception('Your account has been disabled!')
else:
raise Exception('Your username and password were incorrect.')