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 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'accounts') 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"), -- cgit v1.2.1