Created
August 27, 2024 09:56
-
-
Save Liano-HyperionDev/002f617fe307a14a10fa6b1829001a7e to your computer and use it in GitHub Desktop.
Custom for for user Sign Up Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django import forms | |
| from django.contrib.auth.forms import UserCreationForm | |
| from django.contrib.auth import password_validation | |
| from .models import CustomUser | |
| class SignupForm(UserCreationForm): | |
| first_name = forms.CharField(max_length=150, label="First name") | |
| password1 = forms.CharField( | |
| label="Password", | |
| widget=forms.PasswordInput(attrs={'class': 'form-control', 'id': 'password-input'}), | |
| help_text=password_validation.password_validators_help_text_html(), | |
| ) | |
| password2 = forms.CharField( | |
| label="Confirm Password", | |
| widget=forms.PasswordInput(attrs={'class': 'form-control'}), | |
| ) | |
| class Meta: | |
| model = CustomUser | |
| fields = ('first_name','username', 'password1', 'password2') | |
| def save(self, commit=True): | |
| user = super().save(commit=False) | |
| user.first_name = self.cleaned_data["first_name"] | |
| if commit: | |
| user.save() | |
| return user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment