# Path: della/user_manager/forms.py
# class SignupForm(UserCreationForm):
#     username = forms.CharField(max_length=20, validators=[alphanumericu])
#     email = forms.EmailField(max_length=254, required=True)
#     invite_code = forms.CharField(max_length=120)
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.helper = FormHelper()
#         self.helper.layout = Layout(
#             Fieldset(
#                 'Signup',
#                 'invite_code',
#                 'username',
#                 'email',
#                 'password1',
#                 'password2'
#             )
#         )
#         self.helper.form_class = 'form-horizontal'
#         self.helper.form_method = 'post'
#         self.helper.form_action = 'user_manager:signup'
#         self.helper.label_class = 'col-lg-2'
#         self.helper.field_class = 'col-lg-10'
#         self.helper.add_input(Reset('reset', 'Cancel'))
#         self.helper.add_input(Submit('submit', 'Signup'))
# 
#     def clean_invite_code(self):
#         error_message = 'Invalid invite code'
#         invite_code = self.cleaned_data.get('invite_code')
#         if not invite_code == settings.INVITE_CODE:
#             raise forms.ValidationError(error_message)
#         return invite_code
# 
#     def clean_email(self):
#         error_message = 'An user with that email already exists'
#         email = self.cleaned_data.get('email')
#         if email and User.objects.filter(email=email).exists():
#                 raise forms.ValidationError(error_message)
#         return email
# 
#     class Meta:
#         model = User
#         fields = ['email', 'username', ]


from django.views.generic.base import TemplateView
from della.user_manager.forms import SignupForm



class HomePageView(TemplateView):

    template_name = 'home.html'
    template_name_authenticated = 'home_authenticated.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if self.request.user.is_authenticated:
            self.template_name = self.template_name_authenticated

# Path: della/user_manager/forms.py
# class SignupForm(UserCreationForm):
#     username = forms.CharField(max_length=20, validators=[alphanumericu])
#     email = forms.EmailField(max_length=254, required=True)
#     invite_code = forms.CharField(max_length=120)
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.helper = FormHelper()
#         self.helper.layout = Layout(
#             Fieldset(
#                 'Signup',
#                 'invite_code',
#                 'username',
#                 'email',
#                 'password1',
#                 'password2'
#             )
#         )
#         self.helper.form_class = 'form-horizontal'
#         self.helper.form_method = 'post'
#         self.helper.form_action = 'user_manager:signup'
#         self.helper.label_class = 'col-lg-2'
#         self.helper.field_class = 'col-lg-10'
#         self.helper.add_input(Reset('reset', 'Cancel'))
#         self.helper.add_input(Submit('submit', 'Signup'))
# 
#     def clean_invite_code(self):
#         error_message = 'Invalid invite code'
#         invite_code = self.cleaned_data.get('invite_code')
#         if not invite_code == settings.INVITE_CODE:
#             raise forms.ValidationError(error_message)
#         return invite_code
# 
#     def clean_email(self):
#         error_message = 'An user with that email already exists'
#         email = self.cleaned_data.get('email')
#         if email and User.objects.filter(email=email).exists():
#                 raise forms.ValidationError(error_message)
#         return email
# 
#     class Meta:
#         model = User
#         fields = ['email', 'username', ]


# Path: della/views.py
from django.views.generic.base import TemplateView
from della.user_manager.forms import SignupForm




class HomePageView(TemplateView):

    template_name = 'home.html'
    template_name_authenticated = 'home_authenticated.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if self.request.user.is_authenticated:
            self.template_name = self.template_name_authenticated

            return context