1+ from django import forms
2+ from django .contrib .auth .forms import UserCreationForm , AuthenticationForm , PasswordChangeForm , UsernameField , PasswordResetForm , SetPasswordForm
3+ from django .contrib .auth .models import User
4+ from django .utils .translation import gettext_lazy as _
5+
6+
7+ class RegistrationForm (UserCreationForm ):
8+ password1 = forms .CharField (
9+ label = _ ("Password" ),
10+ widget = forms .PasswordInput (attrs = {'class' : 'form-control' , 'placeholder' : 'Password' }),
11+ )
12+ password2 = forms .CharField (
13+ label = _ ("Confirm Password" ),
14+ widget = forms .PasswordInput (attrs = {'class' : 'form-control' , 'placeholder' : 'Confirm Password' }),
15+ )
16+
17+ class Meta :
18+ model = User
19+ fields = ('username' , 'email' , )
20+
21+ widgets = {
22+ 'username' : forms .TextInput (attrs = {
23+ 'class' : 'form-control' ,
24+ 'placeholder' : 'Username'
25+ }),
26+ 'email' : forms .EmailInput (attrs = {
27+ 'class' : 'form-control' ,
28+ 'placeholder' : 'Email'
29+ })
30+ }
31+
32+
33+ class LoginForm (AuthenticationForm ):
34+ username = UsernameField (label = _ ("Your Username" ), widget = forms .TextInput (attrs = {"class" : "form-control" , "placeholder" : "Username" }))
35+ password = forms .CharField (
36+ label = _ ("Your Password" ),
37+ strip = False ,
38+ widget = forms .PasswordInput (attrs = {"class" : "form-control" , "placeholder" : "Password" }),
39+ )
40+
41+ class UserPasswordResetForm (PasswordResetForm ):
42+ email = forms .EmailField (widget = forms .EmailInput (attrs = {
43+ 'class' : 'form-control' ,
44+ 'placeholder' : 'Email'
45+ }))
46+
47+ class UserSetPasswordForm (SetPasswordForm ):
48+ new_password1 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
49+ 'class' : 'form-control' , 'placeholder' : 'New Password'
50+ }), label = "New Password" )
51+ new_password2 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
52+ 'class' : 'form-control' , 'placeholder' : 'Confirm New Password'
53+ }), label = "Confirm New Password" )
54+
55+
56+ class UserPasswordChangeForm (PasswordChangeForm ):
57+ old_password = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
58+ 'class' : 'form-control' , 'placeholder' : 'Old Password'
59+ }), label = 'Old Password' )
60+ new_password1 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
61+ 'class' : 'form-control' , 'placeholder' : 'New Password'
62+ }), label = "New Password" )
63+ new_password2 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
64+ 'class' : 'form-control' , 'placeholder' : 'Confirm New Password'
65+ }), label = "Confirm New Password" )
0 commit comments