mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +00:00
Actually added working password reset functions. Fixed views as required.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user