Skip to content

Commit

Permalink
Allowing for password manipulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
snkashis committed Dec 27, 2011
1 parent a250729 commit 7a89e92
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions cli.py
Expand Up @@ -40,7 +40,24 @@ def delete_user(user_id, access_token):
return True
else:
return False


def modify_user(user_id, password):
url = "https://%s/%s"

try:
d1 = {'access_token': user_id['access_token'], 'password': password}
f1 = urllib2.urlopen(url % (GRAPH_URL, user_id['id']),
data=urllib.urlencode(d1))
content = f1.read()

if content == 'true':
return 'New password of "%s" for %s set.' % (password,user_id['id'],)
else:
return 'Error:Password for %s not changed.' % (user_id['id'],)
except urllib2.HTTPError, e:
error = simplejson.loads(e.read())
print error['error']['message']

def friend_users(user_1, user_2):
url = "https://%s/%s/friends/%s"

Expand Down Expand Up @@ -126,7 +143,7 @@ def question_user(question):
if len(input) != 0:
cmd = input.strip()
if cmd == '?':
print "Command action\n a Add user\n l List users\n m Modify user\n r Reload user list\n d Delete user\n f Friend users\n q Quit"
print "Command action\n a Add user\n l List users\n m Modify user\n r Reload user list\n d Delete user\n f Friend users\n q Quit"
elif cmd == 'a':
installed = question('Installed', ['Y', 'N'])
installed_options = {'Y': 'true', 'N': 'false'}
Expand Down Expand Up @@ -162,6 +179,12 @@ def question_user(question):
users = load_users(app_id, access_token)
elif cmd == 'q' or cmd == 'quit' or cmd == 'exit':
sys.exit(1)

elif cmd =='m':
user_1 = question_user('User ')
password = raw_input("Enter Password: ").strip()
modify_result = modify_user(user_1,password)
print modify_result
else:
print 'Unknown command.'
except (EOFError, KeyboardInterrupt), e:
Expand Down

0 comments on commit 7a89e92

Please sign in to comment.