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.')