diff --git a/elections/migrations/0005_user_full_name.py b/elections/migrations/0005_user_full_name.py new file mode 100644 index 0000000..b6d4181 --- /dev/null +++ b/elections/migrations/0005_user_full_name.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.17 on 2020-12-23 17:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("elections", "0004_auto_20201220_1847"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="full_name", + field=models.CharField( + blank=True, max_length=150, verbose_name="Nom et Prénom" + ), + ), + ] diff --git a/elections/models.py b/elections/models.py index 58befe9..6e714ab 100644 --- a/elections/models.py +++ b/elections/models.py @@ -87,6 +87,7 @@ class User(AbstractUser): blank=True, on_delete=models.CASCADE, ) + full_name = models.CharField(_("Nom et Prénom"), max_length=150, blank=True) @property def base_username(self): diff --git a/elections/utils.py b/elections/utils.py index 36df61a..fea3789 100644 --- a/elections/utils.py +++ b/elections/utils.py @@ -15,7 +15,7 @@ def create_users(election, csv_file): reader = csv.reader(io.StringIO(csv_file.read().decode("utf-8")), dialect) for (username, full_name, email) in reader: election.registered_voters.create( - username=f"{election.id}__{username}", email=email + username=f"{election.id}__{username}", email=email, full_name=full_name ) diff --git a/shared/auth/backends.py b/shared/auth/backends.py index 36b7654..929b295 100644 --- a/shared/auth/backends.py +++ b/shared/auth/backends.py @@ -37,6 +37,7 @@ class ENSCASBackend: """ email = attributes.get("email") + name = attributes.get("name") try: user = UserModel.objects.get(username=cas_login) @@ -44,7 +45,9 @@ class ENSCASBackend: user = None if user is None: - user = UserModel.objects.create_user(username=cas_login, email=email) + user = UserModel.objects.create_user( + username=cas_login, email=email, full_name=name + ) return user # Django boilerplate.