from django import forms
from .models import User
from django.contrib.auth.forms import ReadOnlyPasswordHashField


class UserCreationForm(forms.ModelForm):
    password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
    password2 = forms.CharField(label='Confirm password', widget=forms.PasswordInput)

    class Meta:
        model = User
        fields = ('email', 'full_name')

    def clean_password2(self):
        password1 = self.cleaned_data['password1']
        password2 = self.cleaned_data['password2']
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match!")
        return password2

    def save(self, commit=True):
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])  # or password2
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = ('email', 'password', 'full_name')

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))


class ProfileForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True

    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user', 'phone_number', 'address')
        widgets = {
            'email': forms.EmailInput(attrs={'class': 'form-control'}),
            'full_name': forms.TextInput(attrs={'class': 'form-control'}),
            'special_user': forms.TextInput(attrs={'class': 'form-control'}),
            'phone_number': forms.TextInput(attrs={'class': 'form-control'}),
            'address': forms.Textarea(attrs={'rows': 3, 'col': 10, 'class': 'form-control'})
            }
















8ef8d2d0ea88b3a189eb56df7c5af6f85c8f1aee
<mask token>


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()


    class Meta:
        model = User
        fields = 'email', 'password', 'full_name'

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class':
        'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class':
        'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))


class ProfileForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'
            ].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True


    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user',
            'phone_number', 'address')
        widgets = {'email': forms.EmailInput(attrs={'class': 'form-control'
            }), 'full_name': forms.TextInput(attrs={'class': 'form-control'
            }), 'special_user': forms.TextInput(attrs={'class':
            'form-control'}), 'phone_number': forms.TextInput(attrs={
            'class': 'form-control'}), 'address': forms.Textarea(attrs={
            'rows': 3, 'col': 10, 'class': 'form-control'})}

<mask token>


class UserCreationForm(forms.ModelForm):
    <mask token>
    <mask token>


    class Meta:
        model = User
        fields = 'email', 'full_name'
    <mask token>

    def save(self, commit=True):
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()


    class Meta:
        model = User
        fields = 'email', 'password', 'full_name'

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class':
        'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class':
        'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))


class ProfileForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'
            ].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True


    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user',
            'phone_number', 'address')
        widgets = {'email': forms.EmailInput(attrs={'class': 'form-control'
            }), 'full_name': forms.TextInput(attrs={'class': 'form-control'
            }), 'special_user': forms.TextInput(attrs={'class':
            'form-control'}), 'phone_number': forms.TextInput(attrs={
            'class': 'form-control'}), 'address': forms.Textarea(attrs={
            'rows': 3, 'col': 10, 'class': 'form-control'})}

<mask token>


class UserCreationForm(forms.ModelForm):
    <mask token>
    <mask token>


    class Meta:
        model = User
        fields = 'email', 'full_name'

    def clean_password2(self):
        password1 = self.cleaned_data['password1']
        password2 = self.cleaned_data['password2']
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match!")
        return password2

    def save(self, commit=True):
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()


    class Meta:
        model = User
        fields = 'email', 'password', 'full_name'

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class':
        'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class':
        'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))


class ProfileForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'
            ].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True


    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user',
            'phone_number', 'address')
        widgets = {'email': forms.EmailInput(attrs={'class': 'form-control'
            }), 'full_name': forms.TextInput(attrs={'class': 'form-control'
            }), 'special_user': forms.TextInput(attrs={'class':
            'form-control'}), 'phone_number': forms.TextInput(attrs={
            'class': 'form-control'}), 'address': forms.Textarea(attrs={
            'rows': 3, 'col': 10, 'class': 'form-control'})}

<mask token>


class UserCreationForm(forms.ModelForm):
    password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
    password2 = forms.CharField(label='Confirm password', widget=forms.
        PasswordInput)


    class Meta:
        model = User
        fields = 'email', 'full_name'

    def clean_password2(self):
        password1 = self.cleaned_data['password1']
        password2 = self.cleaned_data['password2']
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match!")
        return password2

    def save(self, commit=True):
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()


    class Meta:
        model = User
        fields = 'email', 'password', 'full_name'

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class':
        'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class':
        'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class':
        'form-control'}))


class ProfileForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'
            ].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True


    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user',
            'phone_number', 'address')
        widgets = {'email': forms.EmailInput(attrs={'class': 'form-control'
            }), 'full_name': forms.TextInput(attrs={'class': 'form-control'
            }), 'special_user': forms.TextInput(attrs={'class':
            'form-control'}), 'phone_number': forms.TextInput(attrs={
            'class': 'form-control'}), 'address': forms.Textarea(attrs={
            'rows': 3, 'col': 10, 'class': 'form-control'})}

from django import forms
from .models import User
from django.contrib.auth.forms import ReadOnlyPasswordHashField


class UserCreationForm(forms.ModelForm):
    password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
    password2 = forms.CharField(label='Confirm password', widget=forms.PasswordInput)

    class Meta:
        model = User
        fields = ('email', 'full_name')

    def clean_password2(self):
        password1 = self.cleaned_data['password1']
        password2 = self.cleaned_data['password2']
        if password1 and password2 and password1 != password2:
            raise forms.ValidationError("Passwords don't match!")
        return password2

    def save(self, commit=True):
        user = super().save(commit=False)
        user.set_password(self.cleaned_data['password1'])  # or password2
        if commit:
            user.save()
        return user


class UserChangeForm(forms.ModelForm):
    password = ReadOnlyPasswordHashField()

    class Meta:
        model = User
        fields = ('email', 'password', 'full_name')

        def clean_password(self):
            return self.initial['password']


class UserRegistrationForm(forms.Form):
    email = forms.EmailField(widget=forms.EmailInput(attrs={'class': 'form-control'}))
    full_name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
    password = forms.CharField(widget=forms.PasswordInput(attrs={'class': 'form-control'}))
    address = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
    phone_number = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))


class ProfileForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user')
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['full_name'].help_text = 'Your full name cannot be more than 200 characters.'
        if not user.is_admin:
            self.fields['email'].disabled = True
            self.fields['is_active'].disabled = True
            self.fields['special_user'].disabled = True

    class Meta:
        model = User
        fields = ('email', 'full_name', 'is_active', 'special_user', 'phone_number', 'address')
        widgets = {
            'email': forms.EmailInput(attrs={'class': 'form-control'}),
            'full_name': forms.TextInput(attrs={'class': 'form-control'}),
            'special_user': forms.TextInput(attrs={'class': 'form-control'}),
            'phone_number': forms.TextInput(attrs={'class': 'form-control'}),
            'address': forms.Textarea(attrs={'rows': 3, 'col': 10, 'class': 'form-control'})
            }















