Actually added working password reset functions. Fixed views as required.

This commit is contained in:
2010-03-18 18:16:18 +00:00
parent 606ddd3cd7
commit 42588e1909
5 changed files with 37 additions and 2 deletions

View File

@@ -50,6 +50,10 @@ class BaseService():
""" Enable a user by uid """
pass
def reset_password(self, uid, password):
""" Reset the user's password """
pass
def login(uid):
""" Login the user and provide cookies back """
pass

View File

@@ -63,4 +63,12 @@ class JabberService(BaseService):
username, server = uid.split("@")
return self.ejctl.enable_user(server, username, password)
def reset_password(self, uid, password):
""" Reset the user's password """
if self.method == "xmpp":
return self.jabberadmin.resetpassword(uid, password)
else:
username, server = uid.split("@")
return self.ejctl.set_password(server, username, password)
ServiceClass = 'JabberService'

View File

@@ -87,6 +87,25 @@ class JabberAdmin():
else:
return False
def resetpassword(self, username, password):
# 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')
values = [ ('hidden', 'FORM_TYPE', 'http://jabber.org/protocol/admin'),
('jid-single', 'accountjid', username),
('text-private', 'password', password) ]
iq = self._construct_form('http://jabber.org/protocol/commands', 'http://jabber.org/protocol/admin#change-user-password', sessionid, values)
# Send request and pray for the best
resp = self._client.SendAndWaitForResponse(iq)
if resp.getAttrs()['type'] == "result":
return True
else:
return False
def checkuser(self, username):
# Send request and get the Session ID

View File

@@ -79,4 +79,8 @@ class MediawikiService(BaseService):
self._db.connection.commit()
pass
def reset_password(self, uid, password):
""" Reset the user's password """
self.enable_user(uid, password)
ServiceClass = 'MediawikiService'

View File

@@ -174,13 +174,13 @@ def service_reset(request, serviceid=0, accept=0):
passwd = hashlib.sha1('%s%s%s' % (acc.service_uid, settings.SECRET_KEY, random.randint(0, 2147483647))).hexdigest()
api = acc.service.api_class
api.enable_user(acc.service_uid, passwd)
if api.reset_password(acc.service_uid, passwd):
error = True
return render_to_response('sso/serviceaccount/resetcomplete.html', locals(), context_instance=RequestContext(request))
return HttpResponseRedirect(reverse('sso.views.profile'))
@login_required
def reddit_add(request):
if request.method == 'POST':