Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support update, reset_password, and delete under Auth endpoints. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions simperium/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,60 @@ def authorize(self, username, password):
response = self._request(self.appname+'/authorize/', data)
return json.loads(response.read())['access_token']

def update(self, username, password, new_username=None, new_password=None):
"""
Updates username or password for a user. Requires both current username
and password.

@username: Username
@password: Password
@new_username: New username (optional)
@new_password: New password (optional)

returns string 'success' if succeed, otherwise throws HTTPError
"""
data = {
'client_id': self.api_key,
'username': username,
'password': password, }
if new_username:
data['new_username'] = new_username
if new_password:
data['new_password'] = new_password
response = self._request(self.appname+'/update/', data)
return json.loads(response.read())['status']

def reset_password(self, username, new_password):
"""
Changes password for a user without current password. Requires API key
with admin privileges.

@username: Username
@new_password: New password

returns string 'success' if succeed, otherwise throws HTTPError
"""
data = {
'username': username,
'new_password': new_password, }
headers = {'X-Simperium-API-Key': '%s' % self.api_key}
response = self._request(self.appname+'/reset_password/', data, headers)
return json.loads(response.read())['status']

def delete(self, username):
"""
Deletes a user and all user data. Requires an API key with admin
privileges.

@username: Username to delete

returns string 'success' if succeed, otherwise throws HTTPError
"""
data = {'username': username}
headers = {'X-Simperium-API-Key': '%s' % self.api_key}
response = self._request(self.appname+'/delete/', data, headers)
return json.loads(response.read())['status']


class Bucket(object):
"""
Expand Down