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