From ce40de14c932c4e48c289b912dad9e2c3631be21 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 13 Dec 2012 15:48:45 -0500 Subject: [PATCH] Add a tool to save/restore user passwords. (imported from commit 59bea04308bc0c42aeef840aa923dbef1919d31d) --- zephyr/management/commands/dump_passwords.py | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 zephyr/management/commands/dump_passwords.py diff --git a/zephyr/management/commands/dump_passwords.py b/zephyr/management/commands/dump_passwords.py new file mode 100644 index 0000000000..0b00c01f23 --- /dev/null +++ b/zephyr/management/commands/dump_passwords.py @@ -0,0 +1,28 @@ +from optparse import make_option +from django.core.management.base import BaseCommand +from zephyr.models import User +import simplejson + +def dump(): + passwords = [] + for u in User.objects.all(): + passwords.append((u.email, u.password)) + file("dumped-passwords", "w").write(simplejson.dumps(passwords) + "\n") + +def restore(change): + for (email, password) in simplejson.loads(file("dumped-passwords").read()): + user = User.objects.get(email__iexact=email) + if change: + user.password = password + user.save() + +class Command(BaseCommand): + option_list = BaseCommand.option_list + ( + make_option('--restore', default=False, action='store_true'), + make_option('--dry-run', '-n', default=False, action='store_true'),) + + def handle(self, *args, **options): + if options["restore"]: + restore(change=not options['dry_run']) + else: + dump()