From b8d9a1344be9968c8505ee230bfcff35d84a6e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Fri, 8 Nov 2019 16:31:43 +0300 Subject: [PATCH] Add hash password --- apps/account/management/commands/add_account.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/account/management/commands/add_account.py b/apps/account/management/commands/add_account.py index 808f661e..2b72767c 100644 --- a/apps/account/management/commands/add_account.py +++ b/apps/account/management/commands/add_account.py @@ -11,7 +11,7 @@ class Command(BaseCommand): def account_sql(self): with connections['legacy'].cursor() as cursor: cursor.execute(''' - select a.email, a.id as account_id + select a.email, a.id as account_id, a.encrypted_password from accounts as a where a.email is not null and a.email not in ('cyril@tomatic.net', @@ -20,7 +20,7 @@ class Command(BaseCommand): 'd.sadykova@octopod.ru', 'n.yurchenko@id-east.ru' ) - and a.confirmed_at is not null + and a.confirmed_at is not null ''') return namedtuplefetchall(cursor) @@ -32,7 +32,12 @@ class Command(BaseCommand): objects.append(User(email=a.email, unconfirmed_email=False, email_confirmed=True, - old_id=a.account_id + old_id=a.account_id, + password='bcrypt$'+a.encrypted_password )) + else: + user = User.objects.filter(Q(email=a.email) | Q(old_id=a.account_id)) + user.update(password='bcrypt$'+a.encrypted_password) + User.objects.bulk_create(objects) self.stdout.write(self.style.WARNING(f'Created accounts objects.')) \ No newline at end of file