summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-09-29 11:45:24 -0500
committerKali Kaneko (leap communications) <kali@leap.se>2016-10-04 01:37:03 -0400
commit8589bd13c7aa9054dc27d8b3be5ede9ebffb6abe (patch)
tree8a0b6c1e8c7cbb4bce09c71bfb4ea4589742ba85 /src
parent082b08a0c856950fc0013da49c8a9d1ffc358f6c (diff)
[feat] list active users
- Resolves: 8488
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/bonafide/_protocol.py7
-rw-r--r--src/leap/bitmask/bonafide/service.py3
-rw-r--r--src/leap/bitmask/cli/user.py20
-rw-r--r--src/leap/bitmask/core/dispatcher.py4
-rw-r--r--src/leap/bitmask/core/web/bitmask.js9
5 files changed, 40 insertions, 3 deletions
diff --git a/src/leap/bitmask/bonafide/_protocol.py b/src/leap/bitmask/bonafide/_protocol.py
index 7917f38..01919c7 100644
--- a/src/leap/bitmask/bonafide/_protocol.py
+++ b/src/leap/bitmask/bonafide/_protocol.py
@@ -147,6 +147,13 @@ class BonafideProtocol(object):
d.addCallback(lambda _: '%s logged out' % full_id)
return d
+ def do_list_users(self):
+ users = []
+ for user, session in self._sessions.items():
+ users.append({'userid': user,
+ 'authenticated': session.is_authenticated})
+ return users
+
def do_change_password(self, full_id, current_password, new_password):
log.msg('Change password for %s' % full_id)
if (full_id not in self._sessions or
diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py
index 1f0d636..fbe6846 100644
--- a/src/leap/bitmask/bonafide/service.py
+++ b/src/leap/bitmask/bonafide/service.py
@@ -106,6 +106,9 @@ class BonafideService(HookableService):
d.addCallback(lambda response: {'logout': 'ok'})
return d
+ def do_list_users(self):
+ return self._bonafide.do_list_users()
+
def do_change_password(self, username, current_password, new_password):
def notify_passphrase_change(_):
data = dict(username=username, password=new_password)
diff --git a/src/leap/bitmask/cli/user.py b/src/leap/bitmask/cli/user.py
index 1c4757e..8d3484c 100644
--- a/src/leap/bitmask/cli/user.py
+++ b/src/leap/bitmask/cli/user.py
@@ -21,6 +21,8 @@ import argparse
import getpass
import sys
+from colorama import Fore
+
from leap.bitmask.cli import command
@@ -35,6 +37,7 @@ SUBCOMMANDS:
create Registers new user, if possible
auth Logs in against the provider
logout Ends any active session with the provider
+ list List users
update Update user password
active Shows the active user, if any
@@ -48,7 +51,7 @@ SUBCOMMANDS:
def create(self, raw_args):
username = self.username(raw_args)
- passwd = self.getpass_twice()
+ passwd = self._getpass_twice()
self.data += ['create', username, passwd, 'true']
return self._send(printer=command.default_dict_printer)
@@ -63,10 +66,14 @@ SUBCOMMANDS:
self.data += ['logout', username]
return self._send(printer=command.default_dict_printer)
+ def list(self, raw_args):
+ self.data += ['list']
+ return self._send(printer=self._print_user_list)
+
def update(self, raw_args):
username = self.username(raw_args)
current_passwd = getpass.getpass('Current password: ')
- new_passwd = self.getpass_twice('New password: ')
+ new_passwd = self._getpass_twice('New password: ')
self.data += ['update', username, current_passwd, new_passwd]
return self._send(printer=command.default_dict_printer)
@@ -87,7 +94,7 @@ SUBCOMMANDS:
return username
- def getpass_twice(self, prompt='Password: '):
+ def _getpass_twice(self, prompt='Password: '):
while True:
passwd1 = getpass.getpass(prompt)
passwd2 = getpass.getpass('Retype the password: ')
@@ -96,3 +103,10 @@ SUBCOMMANDS:
else:
print "The passwords do not match, try again."
print ""
+
+ def _print_user_list(self, users):
+ for u in users:
+ color = ""
+ if u['authenticated']:
+ color = Fore.GREEN
+ print(color + u['userid'] + Fore.RESET)
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 72f9850..a2fd638 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -119,6 +119,10 @@ class UserCmd(SubCommand):
user = parts[2]
return bonafide.do_logout(user)
+ @register_method("[{'userid': str, 'authenticated': bool}]")
+ def do_LIST(self, bonafide, *parts):
+ return bonafide.do_list_users()
+
@register_method("{'update': 'ok'}")
def do_UPDATE(self, bonafide, *parts):
user, current_password, new_password = parts[2], parts[3], parts[4]
diff --git a/src/leap/bitmask/core/web/bitmask.js b/src/leap/bitmask/core/web/bitmask.js
index 554b490..4a837a0 100644
--- a/src/leap/bitmask/core/web/bitmask.js
+++ b/src/leap/bitmask/core/web/bitmask.js
@@ -179,6 +179,15 @@ var bitmask = function(){
},
/**
+ * List users
+ *
+ * @return {Promise<json>} [{'userid': str, 'authenticated': boolean}]
+ */
+ list: function() {
+ return call(['bonafide', 'user', 'list']);
+ },
+
+ /**
* Change password
*
* @param {string} uid The uid to log in