# Path: users/forms.py
# class CustomerUserDelectionForm(forms.ModelForm):
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['password']
# 
#     def clean(self):
#         cleaned_data = super(CustomerUserDelectionForm, self).clean()
# 
#         # Password validation
#         password = cleaned_data.get('password')
#         password_validation = cleaned_data.get('password_validation')
# 
#         password_error_message = _("A senha deve ser igual à confirmação \
#             de senha.")
#         if password and password_validation:
#             if password != password_validation:
#                 password_error = forms.ValidationError(password_error_message)
#                 self.add_error('password', password_error)
# 
#         return cleaned_data
# 
# class CustomerUserRegistrationForm(forms.ModelForm):
#     """
#     Class for CustomerUser registration form.
#     """
#     username = forms.CharField(label=_("Nome de usuário"))
#     first_name = forms.CharField(label=_("Nome"))
#     last_name = forms.CharField(label=_("Sobrenome"))
#     email = forms.CharField(label=_("E-mail"), validators=[validate_email])
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['username', 'first_name', 'last_name', 'email', 'password',
#                   'cellphone', 'phone_number']
# 
#     def clean(self):
#         cleaned_data = super(CustomerUserRegistrationForm, self).clean()
# 
#         # Password validation
#         password = cleaned_data.get('password')
#         password_validation = cleaned_data.get('password_validation')
# 
#         password_error_message = _("A senha deve ser igual à confirmação \
# de senha.")
#         if password and password_validation:
#             if password != password_validation:
#                 password_error = forms.ValidationError(password_error_message)
#                 self.add_error('password', password_error)
# 
#         # Username UNIQUE constraint validation
#         username = cleaned_data.get('username')
# 
#         username_error_message = _("Este nome de usuário não está disponível.")
#         if CustomerUser.objects.filter(username=username).exists():
#             raise ValidationError(username_error_message)
# 
#         return cleaned_data
# 
# class CustomerUserUpdateForm(forms.ModelForm):
#     """
#     class for CustomerUser update form
#     """
# 
#     username = forms.CharField(label=_("Nome de usuário"))
#     first_name = forms.CharField(label=_("Nome"))
#     last_name = forms.CharField(label=_("Sobrenome"))
#     email = forms.CharField(label=_("E-mail"), validators=[validate_email])
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['username', 'first_name', 'last_name', 'email', 'password']
# 
# class LoginForm(forms.Form):
#     """
#     Class for Costumer User Login form
#     """
# 
#     username = forms.CharField(label=_("Nome de usuário"))
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
# 
# Path: users/models.py
# class CustomerUser(User):
#     """docstring for CustomerUser"""
#     cellphone = models.CharField(
#         help_text=_("Número de telefone. Preencha apenas com númreos."),
#         verbose_name=_("Telefone Celular"),
#         max_length=15, null=False, blank=False)
# 
#     phone_number = models.CharField(
#         help_text=_("Número de telefone. Preencha apenas com númreos."),
#         verbose_name=_("Teledone Fixo"),
#         max_length=15, null=True, blank=False)
# 
#     class Meta:
#         verbose_name = _('Cliente')
#         verbose_name_plural = _('Clientes')
# 
#     def __str__(self):
#         return (self.first_name + " " + self.last_name)


from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import DetailView, ListView
from django.views.generic.edit import FormView, UpdateView
from users.forms import (
    CustomerUserDelectionForm,
    CustomerUserRegistrationForm,
    CustomerUserUpdateForm,
    LoginForm)
from .models import CustomerUser
                user.delete()
                messages.sucess(request, 'Sua conta foi excluída')
                response = render(request, 'signup.html')
                return response
            else:
                pass

        else:
            response = render(request, 'excluirConta.html', {'form': form})

        return response


@auth_view_decorator(login_required(login_url='/users/login/'))
class CustomerUserUpdateView(UpdateView):
    """
    Class for CustomerUser edit/update view implementation
    """

    model = CustomerUser
    slug_field = 'id'
    pk_url_kwarg = 'id'
    fields = ['username', 'first_name', 'last_name', 'email', 'password']

    def get_queryset(self):
        return CustomerUser.objects.all()

    def get(self, request, id):
        if request.user.id == int(id):
            instance = CustomerUser.objects.get(id=id)

# Path: users/forms.py
# class CustomerUserDelectionForm(forms.ModelForm):
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['password']
# 
#     def clean(self):
#         cleaned_data = super(CustomerUserDelectionForm, self).clean()
# 
#         # Password validation
#         password = cleaned_data.get('password')
#         password_validation = cleaned_data.get('password_validation')
# 
#         password_error_message = _("A senha deve ser igual à confirmação \
#             de senha.")
#         if password and password_validation:
#             if password != password_validation:
#                 password_error = forms.ValidationError(password_error_message)
#                 self.add_error('password', password_error)
# 
#         return cleaned_data
# 
# class CustomerUserRegistrationForm(forms.ModelForm):
#     """
#     Class for CustomerUser registration form.
#     """
#     username = forms.CharField(label=_("Nome de usuário"))
#     first_name = forms.CharField(label=_("Nome"))
#     last_name = forms.CharField(label=_("Sobrenome"))
#     email = forms.CharField(label=_("E-mail"), validators=[validate_email])
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['username', 'first_name', 'last_name', 'email', 'password',
#                   'cellphone', 'phone_number']
# 
#     def clean(self):
#         cleaned_data = super(CustomerUserRegistrationForm, self).clean()
# 
#         # Password validation
#         password = cleaned_data.get('password')
#         password_validation = cleaned_data.get('password_validation')
# 
#         password_error_message = _("A senha deve ser igual à confirmação \
# de senha.")
#         if password and password_validation:
#             if password != password_validation:
#                 password_error = forms.ValidationError(password_error_message)
#                 self.add_error('password', password_error)
# 
#         # Username UNIQUE constraint validation
#         username = cleaned_data.get('username')
# 
#         username_error_message = _("Este nome de usuário não está disponível.")
#         if CustomerUser.objects.filter(username=username).exists():
#             raise ValidationError(username_error_message)
# 
#         return cleaned_data
# 
# class CustomerUserUpdateForm(forms.ModelForm):
#     """
#     class for CustomerUser update form
#     """
# 
#     username = forms.CharField(label=_("Nome de usuário"))
#     first_name = forms.CharField(label=_("Nome"))
#     last_name = forms.CharField(label=_("Sobrenome"))
#     email = forms.CharField(label=_("E-mail"), validators=[validate_email])
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
#     password_validation = forms.\
#         CharField(label=_("Confirmação de senha"), widget=forms.PasswordInput)
# 
#     class Meta:
#         model = CustomerUser
#         fields = ['username', 'first_name', 'last_name', 'email', 'password']
# 
# class LoginForm(forms.Form):
#     """
#     Class for Costumer User Login form
#     """
# 
#     username = forms.CharField(label=_("Nome de usuário"))
#     password = forms.CharField(label=_("Senha"), widget=forms.PasswordInput)
# 
# Path: users/models.py
# class CustomerUser(User):
#     """docstring for CustomerUser"""
#     cellphone = models.CharField(
#         help_text=_("Número de telefone. Preencha apenas com númreos."),
#         verbose_name=_("Telefone Celular"),
#         max_length=15, null=False, blank=False)
# 
#     phone_number = models.CharField(
#         help_text=_("Número de telefone. Preencha apenas com númreos."),
#         verbose_name=_("Teledone Fixo"),
#         max_length=15, null=True, blank=False)
# 
#     class Meta:
#         verbose_name = _('Cliente')
#         verbose_name_plural = _('Clientes')
# 
#     def __str__(self):
#         return (self.first_name + " " + self.last_name)


# Path: users/views.py
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import redirect, render
from django.utils.decorators import method_decorator
from django.views.generic import DetailView, ListView
from django.views.generic.edit import FormView, UpdateView
from users.forms import (
    CustomerUserDelectionForm,
    CustomerUserRegistrationForm,
    CustomerUserUpdateForm,
    LoginForm)
from .models import CustomerUser

                user.delete()
                messages.sucess(request, 'Sua conta foi excluída')
                response = render(request, 'signup.html')
                return response
            else:
                pass

        else:
            response = render(request, 'excluirConta.html', {'form': form})

        return response


@auth_view_decorator(login_required(login_url='/users/login/'))
class CustomerUserUpdateView(UpdateView):
    """
    Class for CustomerUser edit/update view implementation
    """

    model = CustomerUser
    slug_field = 'id'
    pk_url_kwarg = 'id'
    fields = ['username', 'first_name', 'last_name', 'email', 'password']

    def get_queryset(self):
        return CustomerUser.objects.all()

    def get(self, request, id):
        if request.user.id == int(id):
            instance = CustomerUser.objects.get(id=id)

            form = CustomerUserUpdateForm(request.POST or None,