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 = _ ("Password Confirmation" ),
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 (widget = forms .TextInput (attrs = {"class" : "form-control" , "placeholder" : "Username" }))
35+ password = forms .CharField (
36+ label = _ ("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' ,
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