2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2013-07-29 23:03:31 +02:00
|
|
|
from zerver.lib.initial_password import initial_password
|
2017-07-18 19:28:16 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2012-10-10 20:42:04 +02:00
|
|
|
|
2017-07-18 19:28:16 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
2012-10-12 17:10:59 +02:00
|
|
|
help = "Print the initial password and API key for accounts as created by populate_db"
|
|
|
|
|
|
|
|
fmt = '%-30s %-16s %-32s'
|
2012-10-10 20:42:04 +02:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('emails', metavar='<email>', type=str, nargs='*',
|
|
|
|
help="email of user to show password and API key for")
|
2017-07-18 19:28:16 +02:00
|
|
|
self.add_realm_args(parser)
|
2015-08-21 02:10:41 +02:00
|
|
|
|
2012-10-10 20:42:04 +02:00
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
2017-07-18 19:28:16 +02:00
|
|
|
realm = self.get_realm(options)
|
2015-11-01 17:11:06 +01:00
|
|
|
print(self.fmt % ('email', 'password', 'API key'))
|
2015-08-21 02:10:41 +02:00
|
|
|
for email in options['emails']:
|
2012-10-10 20:42:04 +02:00
|
|
|
if '@' not in email:
|
2015-11-01 17:11:06 +01:00
|
|
|
print('ERROR: %s does not look like an email address' % (email,))
|
2012-10-10 20:42:04 +02:00
|
|
|
continue
|
2017-07-18 19:28:16 +02:00
|
|
|
print(self.fmt % (email, initial_password(email), self.get_user(email, realm).api_key))
|