Commit 4670b51c authored by Birin Sanchez's avatar Birin Sanchez
Browse files

* Make recovery email non unique.


* Remove non_unique_email command.
* Add command populate_recovery_email.
Signed-off-by: Birin Sanchez's avatarBirin Sanchez <birin.sanchez@puri.sm>
parent 0f69fcc9
Pipeline #12706 passed with stage
in 40 seconds
from django.core.management.base import BaseCommand
from purist.models import User
class Command(BaseCommand):
help = 'Shows what recovery emails are used in more than one account.'
def handle(self, *args, **options):
sql_query = 'SELECT id,email,COUNT(email) AS count from purist_user \
GROUP BY email HAVING COUNT(email) > 1'
query = User.objects.raw(sql_query)
msg1 = "\nRecovery email '{}' is used {} times by the following users:"
msg2 = ' {}'
for item in query:
print(msg1.format(item.email, item.count))
users = User.objects.filter(email=item.email)
for user in users:
print(msg2.format(user.username))
from django.core.management.base import BaseCommand
from purist.models import User
import time
class Command(BaseCommand):
help = "Populate User.email (recovery email) with User.get_identity() for \
users that did not add a recovery email a the time of registration."
def add_arguments(self, parser):
parser.add_argument('--wait',
type=int,
help='Number of seconds to wait between users. \
Default is 0.',
default=0)
def handle(self, *args, **options):
wait_time = options['wait']
usrs_empty = User.objects.filter(email='')
self.stdout.write('Processing users with no recovery email')
for user in usrs_empty:
user.email = user.get_identity()
user.save()
self.stdout.write(' User {}:'.format(user.username))
self.stdout.write(' New recovery email: {}'.format(
user.email))
time.sleep(wait_time)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.20 on 2019-05-22 15:42
from __future__ import unicode_literals
from django.db import migrations, models
import purist.models
class Migration(migrations.Migration):
dependencies = [
('purist', '0005_add_billing_email'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=254, verbose_name='email address'),
),
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(error_messages={'unique': 'An account with that address already exists.'}, help_text='Start with a letter, followed by letters or numbers.', max_length=150, unique=True, validators=[purist.models.UsernameValidator()], verbose_name='username'),
),
]
......@@ -81,7 +81,7 @@ class User(AbstractUser):
'unique': _("An account with that address already exists."),
},
)
email = models.EmailField(_('email address'), blank=False, unique=True) # recovery email address
email = models.EmailField(_('email address'), blank=False, unique=False) # recovery email address
tunnel_user = models.CharField(max_length=250, default=None, null=True)
tunnel_password = models.CharField(max_length=250, default=None, null=True)
account_type = EnumIntegerField(enum=AccountType,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment