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' : 'Retype password' }),
14+ )
15+ class Meta :
16+ model = User
17+ fields = ('username' , 'email' , )
18+
19+ widgets = {
20+ 'username' : forms .TextInput (attrs = {
21+ 'class' : 'form-control' ,
22+ 'placeholder' : 'Username'
23+ }),
24+ 'email' : forms .EmailInput (attrs = {
25+ 'class' : 'form-control' ,
26+ 'placeholder' : 'Email'
27+ })
28+ }
29+
30+ class LoginForm (AuthenticationForm ):
31+ username = UsernameField (widget = forms .TextInput (attrs = {
32+ 'class' : 'form-control' ,
33+ 'placeholder' : 'Username'
34+ }))
35+ password = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
36+ 'class' : 'form-control' ,
37+ 'placeholder' : 'Password'
38+ }))
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' ,
50+ 'placeholder' : 'New Password'
51+ }), label = "New Password" )
52+ new_password2 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
53+ 'class' : 'form-control' ,
54+ 'placeholder' : 'Confirm New Password'
55+ }), label = "Confirm New Password" )
56+
57+
58+ class UserPasswordChangeForm (PasswordChangeForm ):
59+ old_password = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
60+ 'class' : 'form-control' ,
61+ 'placeholder' : 'Old Password'
62+ }), label = 'Old Password' )
63+ new_password1 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
64+ 'class' : 'form-control' ,
65+ 'placeholder' : 'New Password'
66+ }), label = "New Password" )
67+ new_password2 = forms .CharField (max_length = 50 , widget = forms .PasswordInput (attrs = {
68+ 'class' : 'form-control' ,
69+ 'placeholder' : 'Confirm New Password'
70+ }), label = "Confirm New Password" )
0 commit comments