From b1398dfeff7923c9bc13096aaaa4ce6ab7b4b029 Mon Sep 17 00:00:00 2001 From: Andrea Lepori Date: Sun, 30 Jul 2023 15:52:49 +0200 Subject: add email field when registering --- accounts/views.py | 15 +++++++++++++++ version.txt | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/accounts/views.py b/accounts/views.py index 47b66a2..dc53660 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,4 +1,5 @@ import datetime +from django import forms from django.shortcuts import render from django.urls import reverse from django.conf import settings @@ -43,12 +44,26 @@ MIDATA_ENABLED = settings.OAUTH_ENABLED # override to remove help text class RegisterForm(UserCreationForm): + email = forms.EmailField(required=True) + + class Meta: + model = User + fields = ("username", "email", "password1", "password2") + def __init__(self, *args, **kwargs): super(UserCreationForm, self).__init__(*args, **kwargs) for fieldname in ['username', 'password1', 'password2']: self.fields[fieldname].help_text = None + def save(self, commit=True): + user = super().save() + user.set_password(self.cleaned_data["password1"]) + user.email = self.cleaned_data["email"] + if commit: + user.save() + return user + class AuthForm(AuthenticationForm): error_messages = { 'invalid_login': ("Password errata e/o utente inesistente"), diff --git a/version.txt b/version.txt index 9ffce4e..962f641 100644 --- a/version.txt +++ b/version.txt @@ -1,2 +1,2 @@ version=0.7 -rev=1 +rev=2 -- cgit v1.2.1