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):
|
||||
pass
|
||||
|
||||
class ServiceError(Exception):
|
||||
pass
|
||||
|
||||
## Models
|
||||
|
||||
class SSOUser(models.Model):
|
||||
@@ -129,6 +132,8 @@ class ServiceAccount(models.Model):
|
||||
|
||||
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)
|
||||
if not self.service_uid:
|
||||
raise ServiceError('Error occured while trying to create the Service Account, please try again later')
|
||||
else:
|
||||
raise ExistingUser('Username %s has already been took' % self.username)
|
||||
else:
|
||||
|
||||
@@ -16,7 +16,6 @@ class JabberService(BaseService):
|
||||
if settings.JABBER_METHOD == "xmpp":
|
||||
self.method = "xmpp"
|
||||
self.jabberadmin = JabberAdmin(settings.JABBER_SERVER, settings.JABBER_AUTH_USER, settings.JABBER_AUTH_PASSWD)
|
||||
self.jabberadmin.connect()
|
||||
else:
|
||||
self.method = "cmd"
|
||||
self.ejctl = eJabberdCtl(sudo=settings.JABBER_SUDO)
|
||||
|
||||
@@ -22,14 +22,14 @@ class JabberAdmin():
|
||||
self._client.disconnect()
|
||||
|
||||
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))
|
||||
client.auth(self.username, self.password)
|
||||
client.sendInitPresence()
|
||||
|
||||
self._client = client
|
||||
self._client = client
|
||||
|
||||
def _construct_iq_req(self, xmlns, node):
|
||||
n = xmpp.Node('command', attrs={'xmlns': xmlns, 'node': node})
|
||||
@@ -49,6 +49,10 @@ class JabberAdmin():
|
||||
|
||||
|
||||
def adduser(self, username, password):
|
||||
try:
|
||||
self.connect()
|
||||
except:
|
||||
return False
|
||||
# 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'))
|
||||
sessionid = resp.getTagAttr('command','sessionid')
|
||||
@@ -70,6 +74,10 @@ class JabberAdmin():
|
||||
|
||||
|
||||
def deluser(self, username):
|
||||
try:
|
||||
self.connect()
|
||||
except:
|
||||
return False
|
||||
# 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'))
|
||||
sessionid = resp.getTagAttr('command','sessionid')
|
||||
@@ -88,6 +96,10 @@ class JabberAdmin():
|
||||
return False
|
||||
|
||||
def resetpassword(self, username, password):
|
||||
try:
|
||||
self.connect()
|
||||
except:
|
||||
return False
|
||||
# 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'))
|
||||
sessionid = resp.getTagAttr('command','sessionid')
|
||||
@@ -108,6 +120,10 @@ class JabberAdmin():
|
||||
|
||||
|
||||
def checkuser(self, username):
|
||||
try:
|
||||
self.connect()
|
||||
except:
|
||||
return False
|
||||
# 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'))
|
||||
sessionid = resp.getTagAttr('command','sessionid')
|
||||
|
||||
@@ -130,6 +130,8 @@ def service_add(request):
|
||||
acc.save()
|
||||
except ExistingUser:
|
||||
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:
|
||||
error = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user