mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
More error checking on Jabber, also presents error message to user if service addition fails
This commit is contained in:
@@ -17,6 +17,9 @@ class CorporateOnlyService(Exception):
|
|||||||
class ExistingUser(Exception):
|
class ExistingUser(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class ServiceError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
## Models
|
## Models
|
||||||
|
|
||||||
class SSOUser(models.Model):
|
class SSOUser(models.Model):
|
||||||
@@ -129,6 +132,8 @@ class ServiceAccount(models.Model):
|
|||||||
|
|
||||||
reddit = RedditAccount.objects.filter(user=self.user)
|
reddit = RedditAccount.objects.filter(user=self.user)
|
||||||
self.service_uid = api.add_user(self.username, self.password, user=self.user, character=self.character, eveapi=eveapi, reddit=reddit)
|
self.service_uid = api.add_user(self.username, self.password, user=self.user, character=self.character, eveapi=eveapi, reddit=reddit)
|
||||||
|
if not self.service_uid:
|
||||||
|
raise ServiceError('Error occured while trying to create the Service Account, please try again later')
|
||||||
else:
|
else:
|
||||||
raise ExistingUser('Username %s has already been took' % self.username)
|
raise ExistingUser('Username %s has already been took' % self.username)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ class JabberService(BaseService):
|
|||||||
if settings.JABBER_METHOD == "xmpp":
|
if settings.JABBER_METHOD == "xmpp":
|
||||||
self.method = "xmpp"
|
self.method = "xmpp"
|
||||||
self.jabberadmin = JabberAdmin(settings.JABBER_SERVER, settings.JABBER_AUTH_USER, settings.JABBER_AUTH_PASSWD)
|
self.jabberadmin = JabberAdmin(settings.JABBER_SERVER, settings.JABBER_AUTH_USER, settings.JABBER_AUTH_PASSWD)
|
||||||
self.jabberadmin.connect()
|
|
||||||
else:
|
else:
|
||||||
self.method = "cmd"
|
self.method = "cmd"
|
||||||
self.ejctl = eJabberdCtl(sudo=settings.JABBER_SUDO)
|
self.ejctl = eJabberdCtl(sudo=settings.JABBER_SUDO)
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ class JabberAdmin():
|
|||||||
self._client.disconnect()
|
self._client.disconnect()
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
if not hasattr(self, '_client'):
|
||||||
|
client = xmpp.Client(self.jid.getDomain(), debug=[])
|
||||||
|
|
||||||
client = xmpp.Client(self.jid.getDomain(), debug=[])
|
client.connect(server=('dredd.it', 5222))
|
||||||
|
client.auth(self.username, self.password)
|
||||||
|
client.sendInitPresence()
|
||||||
|
|
||||||
client.connect(server=('dredd.it', 5222))
|
self._client = client
|
||||||
client.auth(self.username, self.password)
|
|
||||||
client.sendInitPresence()
|
|
||||||
|
|
||||||
self._client = client
|
|
||||||
|
|
||||||
def _construct_iq_req(self, xmlns, node):
|
def _construct_iq_req(self, xmlns, node):
|
||||||
n = xmpp.Node('command', attrs={'xmlns': xmlns, 'node': node})
|
n = xmpp.Node('command', attrs={'xmlns': xmlns, 'node': node})
|
||||||
@@ -49,6 +49,10 @@ class JabberAdmin():
|
|||||||
|
|
||||||
|
|
||||||
def adduser(self, username, password):
|
def adduser(self, username, password):
|
||||||
|
try:
|
||||||
|
self.connect()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
# Send request and get the Session ID
|
# Send request and get the Session ID
|
||||||
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#add-user'))
|
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#add-user'))
|
||||||
sessionid = resp.getTagAttr('command','sessionid')
|
sessionid = resp.getTagAttr('command','sessionid')
|
||||||
@@ -70,6 +74,10 @@ class JabberAdmin():
|
|||||||
|
|
||||||
|
|
||||||
def deluser(self, username):
|
def deluser(self, username):
|
||||||
|
try:
|
||||||
|
self.connect()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
# Send request and get the Session ID
|
# Send request and get the Session ID
|
||||||
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#delete-user'))
|
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#delete-user'))
|
||||||
sessionid = resp.getTagAttr('command','sessionid')
|
sessionid = resp.getTagAttr('command','sessionid')
|
||||||
@@ -88,6 +96,10 @@ class JabberAdmin():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def resetpassword(self, username, password):
|
def resetpassword(self, username, password):
|
||||||
|
try:
|
||||||
|
self.connect()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
# Send request and get the Session ID
|
# Send request and get the Session ID
|
||||||
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#change-user-password'))
|
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#change-user-password'))
|
||||||
sessionid = resp.getTagAttr('command','sessionid')
|
sessionid = resp.getTagAttr('command','sessionid')
|
||||||
@@ -108,6 +120,10 @@ class JabberAdmin():
|
|||||||
|
|
||||||
|
|
||||||
def checkuser(self, username):
|
def checkuser(self, username):
|
||||||
|
try:
|
||||||
|
self.connect()
|
||||||
|
except:
|
||||||
|
return False
|
||||||
# Send request and get the Session ID
|
# Send request and get the Session ID
|
||||||
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#get-user-password'))
|
resp = self._client.SendAndWaitForResponse(self._construct_iq_req('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#get-user-password'))
|
||||||
sessionid = resp.getTagAttr('command','sessionid')
|
sessionid = resp.getTagAttr('command','sessionid')
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ def service_add(request):
|
|||||||
acc.save()
|
acc.save()
|
||||||
except ExistingUser:
|
except ExistingUser:
|
||||||
error = "User by this name already exists, your account has not been created"
|
error = "User by this name already exists, your account has not been created"
|
||||||
|
except ServiceError:
|
||||||
|
error = "A error occured while trying to create the Service Account, please try again later"
|
||||||
else:
|
else:
|
||||||
error = None
|
error = None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user