2017-11-16 00:55:49 +01:00
|
|
|
from argparse import ArgumentParser
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
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
|
2018-08-01 10:53:40 +02:00
|
|
|
from zerver.lib.users import get_api_key
|
2012-10-10 20:42:04 +02:00
|
|
|
|
2020-01-14 21:59:46 +01: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
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def add_arguments(self, parser: 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
|
|
|
|
2017-10-27 12:57:54 +02:00
|
|
|
def handle(self, *args: Any, **options: 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:
|
2020-06-10 06:41:04 +02:00
|
|
|
print(f'ERROR: {email} does not look like an email address')
|
2012-10-10 20:42:04 +02:00
|
|
|
continue
|
2018-08-01 10:53:40 +02:00
|
|
|
user = self.get_user(email, realm)
|
|
|
|
print(self.fmt % (email, initial_password(email), get_api_key(user)))
|