Commit d8ba91b2f1b551701079e83b27ea1b0e28caac00

Authored by Carlos Coêlho
1 parent 16a3f001

Normalized empty passwords for resetting

Since Django considers empty password unusable, we must set one in order
to allow users that have no password set to reset their passwords.

Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
colab/accounts/migrations/0005_auto_20150312_1454.py 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +# -*- coding: utf-8 -*-
  2 +from __future__ import unicode_literals
  3 +
  4 +from django.contrib.auth.hashers import make_password
  5 +from django.db import models, migrations
  6 +from django.utils.crypto import get_random_string
  7 +
  8 +
  9 +def normalize_password(apps, schema_editor):
  10 + User = apps.get_model("accounts", "User")
  11 + for user in User.objects.all():
  12 + if len(user.password) is not 0:
  13 + continue
  14 +
  15 + rand_pwd = get_random_string()
  16 +
  17 + user.password = make_password(rand_pwd)
  18 + user.save()
  19 +
  20 +
  21 +class Migration(migrations.Migration):
  22 +
  23 + dependencies = [
  24 + ('accounts', '0004_auto_20150311_1818'),
  25 + ]
  26 +
  27 + operations = [
  28 + migrations.RunPython(normalize_password)
  29 + ]
... ...