# Path: brasilcomvc/common/views.py
# class AnonymousRequiredMixin(object):
# 
#     '''
#     Make any view be accessible by unauthenticated users only
#     '''
# 
#     def dispatch(self, request, *args, **kwargs):
#         if request.user.is_authenticated():
#             return redirect(settings.LOGIN_REDIRECT_URL)
#         return super(AnonymousRequiredMixin, self).dispatch(
#             request, *args, **kwargs)
# 
# class LoginRequiredMixin(object):
# 
#     '''
#     Bind login requirement to any view
#     '''
# 
#     @method_decorator(login_required)
#     def dispatch(self, *args, **kwargs):
#         return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
# 
# Path: brasilcomvc/accounts/forms.py
# class EditNotificationsForm(forms.ModelForm):
# 
#     class Meta:
#         model = User
#         fields = ('email_newsletter',)
#         labels = {
#             'email_newsletter': 'Receber novidades sobre o Brasil.com.vc',
#         }
# 
# class DeleteUserForm(forms.Form):
# 
#     password = forms.CharField(label='Senha', widget=forms.PasswordInput)
# 
#     def __init__(self, user, *args, **kwargs):
#         super(DeleteUserForm, self).__init__(*args, **kwargs)
#         self.user = user
# 
#     def clean_password(self):
#         password = self.cleaned_data['password']
#         if not self.user.check_password(password):
#             self.add_error('password', 'Senha inválida')
#         return password
# 
# class LoginForm(AuthenticationForm):
# 
#     # this is named username so we can use Django's login view
#     username = forms.EmailField(required=True)
# 
# class PasswordResetForm(djangoPasswordResetForm):
#     '''
#     Override the built-in form to customize email sending
#     '''
# 
#     def save(
#             self, use_https=False, token_generator=default_token_generator,
#             from_email=None, domain_override=None, request=None, **kwargs):
#         try:
#             user = User.objects.get(email=self.cleaned_data['email'])
#         except User.DoesNotExist:
#             return
# 
#         if not user.has_usable_password():
#             return
# 
#         if domain_override:
#             site_name = domain = domain_override
#         else:
#             current_site = get_current_site(request)
#             site_name = current_site.name
#             domain = current_site.domain
# 
#         context = {
#             'email': user.email,
#             'domain': domain,
#             'site_name': site_name,
#             'uid': urlsafe_base64_encode(force_bytes(user.pk)),
#             'user': user,
#             'token': token_generator.make_token(user),
#             'protocol': 'https' if use_https else 'http',
#         }
#         context['reset_link'] = '{protocol}://{domain}{url}'.format(
#             url=reverse('accounts:password_reset_confirm', kwargs={
#                 'uidb64': context['uid'], 'token': context['token']}),
#             **context)
# 
#         send_template_email(
#             subject='Redefinição de senha',
#             to=self.cleaned_data['email'],
#             template_name='emails/password_reset.html',
#             context=context)
# 
# class SignupForm(forms.ModelForm):
# 
#     password = forms.CharField(label='Senha', widget=forms.PasswordInput)
# 
#     class Meta:
#         model = User
#         fields = ('full_name', 'email',)
# 
#     def save(self, **kwargs):
#         # Set password from user input
#         self.instance.set_password(self.cleaned_data['password'])
#         return super(SignupForm, self).save(**kwargs)
# 
# class UserAddressForm(forms.ModelForm):
# 
#     class Meta:
#         model = UserAddress
#         fields = '__all__'
# 
#     def __init__(self, *args, **kwargs):
#         super(UserAddressForm, self).__init__(*args, **kwargs)
# 
#         # Limit regions to available cities
#         states = Region.objects.filter(
#             id__in=set(City.objects.values_list('region_id', flat=True)))
#         self.fields['state'].queryset = states
#         self.fields['state'].choices = states.values_list('id', 'name')
# 
#         # Group cities by region (state)
#         self.fields['city'].choices = self._group_cities()
# 
#     def _group_cities(self):
#         '''
#         Build a choices-like list with all cities grouped by state (region)
#         '''
#         return [
#             (state, [(city.pk, city.name) for city in cities],)
#             for state, cities in groupby(
#                 self.fields['city'].queryset.order_by('region__name', 'name'),
#                 lambda city: city.region.name)]


from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth import (
    authenticate,
    login as login_user,
    logout as logout_user)
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.views import (
    login as auth_login,
    password_reset as django_password_reset,
    password_reset_confirm as django_password_reset_confirm,
    password_reset_done as django_password_reset_done)
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.views.generic import (
    CreateView,
    FormView,
    UpdateView)
from brasilcomvc.common.views import AnonymousRequiredMixin, LoginRequiredMixin
from .forms import (
    EditNotificationsForm,
    DeleteUserForm,
    LoginForm,
    PasswordResetForm,
    SignupForm,
    UserAddressForm)
# coding: utf8
from __future__ import unicode_literals




class Signup(AnonymousRequiredMixin, CreateView):
    '''
    User Signup
    '''


# Path: brasilcomvc/common/views.py
# class AnonymousRequiredMixin(object):
# 
#     '''
#     Make any view be accessible by unauthenticated users only
#     '''
# 
#     def dispatch(self, request, *args, **kwargs):
#         if request.user.is_authenticated():
#             return redirect(settings.LOGIN_REDIRECT_URL)
#         return super(AnonymousRequiredMixin, self).dispatch(
#             request, *args, **kwargs)
# 
# class LoginRequiredMixin(object):
# 
#     '''
#     Bind login requirement to any view
#     '''
# 
#     @method_decorator(login_required)
#     def dispatch(self, *args, **kwargs):
#         return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
# 
# Path: brasilcomvc/accounts/forms.py
# class EditNotificationsForm(forms.ModelForm):
# 
#     class Meta:
#         model = User
#         fields = ('email_newsletter',)
#         labels = {
#             'email_newsletter': 'Receber novidades sobre o Brasil.com.vc',
#         }
# 
# class DeleteUserForm(forms.Form):
# 
#     password = forms.CharField(label='Senha', widget=forms.PasswordInput)
# 
#     def __init__(self, user, *args, **kwargs):
#         super(DeleteUserForm, self).__init__(*args, **kwargs)
#         self.user = user
# 
#     def clean_password(self):
#         password = self.cleaned_data['password']
#         if not self.user.check_password(password):
#             self.add_error('password', 'Senha inválida')
#         return password
# 
# class LoginForm(AuthenticationForm):
# 
#     # this is named username so we can use Django's login view
#     username = forms.EmailField(required=True)
# 
# class PasswordResetForm(djangoPasswordResetForm):
#     '''
#     Override the built-in form to customize email sending
#     '''
# 
#     def save(
#             self, use_https=False, token_generator=default_token_generator,
#             from_email=None, domain_override=None, request=None, **kwargs):
#         try:
#             user = User.objects.get(email=self.cleaned_data['email'])
#         except User.DoesNotExist:
#             return
# 
#         if not user.has_usable_password():
#             return
# 
#         if domain_override:
#             site_name = domain = domain_override
#         else:
#             current_site = get_current_site(request)
#             site_name = current_site.name
#             domain = current_site.domain
# 
#         context = {
#             'email': user.email,
#             'domain': domain,
#             'site_name': site_name,
#             'uid': urlsafe_base64_encode(force_bytes(user.pk)),
#             'user': user,
#             'token': token_generator.make_token(user),
#             'protocol': 'https' if use_https else 'http',
#         }
#         context['reset_link'] = '{protocol}://{domain}{url}'.format(
#             url=reverse('accounts:password_reset_confirm', kwargs={
#                 'uidb64': context['uid'], 'token': context['token']}),
#             **context)
# 
#         send_template_email(
#             subject='Redefinição de senha',
#             to=self.cleaned_data['email'],
#             template_name='emails/password_reset.html',
#             context=context)
# 
# class SignupForm(forms.ModelForm):
# 
#     password = forms.CharField(label='Senha', widget=forms.PasswordInput)
# 
#     class Meta:
#         model = User
#         fields = ('full_name', 'email',)
# 
#     def save(self, **kwargs):
#         # Set password from user input
#         self.instance.set_password(self.cleaned_data['password'])
#         return super(SignupForm, self).save(**kwargs)
# 
# class UserAddressForm(forms.ModelForm):
# 
#     class Meta:
#         model = UserAddress
#         fields = '__all__'
# 
#     def __init__(self, *args, **kwargs):
#         super(UserAddressForm, self).__init__(*args, **kwargs)
# 
#         # Limit regions to available cities
#         states = Region.objects.filter(
#             id__in=set(City.objects.values_list('region_id', flat=True)))
#         self.fields['state'].queryset = states
#         self.fields['state'].choices = states.values_list('id', 'name')
# 
#         # Group cities by region (state)
#         self.fields['city'].choices = self._group_cities()
# 
#     def _group_cities(self):
#         '''
#         Build a choices-like list with all cities grouped by state (region)
#         '''
#         return [
#             (state, [(city.pk, city.name) for city in cities],)
#             for state, cities in groupby(
#                 self.fields['city'].queryset.order_by('region__name', 'name'),
#                 lambda city: city.region.name)]


# Path: brasilcomvc/accounts/views.py
from django.core.urlresolvers import reverse, reverse_lazy
from django.contrib.auth import (
    authenticate,
    login as login_user,
    logout as logout_user)
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.views import (
    login as auth_login,
    password_reset as django_password_reset,
    password_reset_confirm as django_password_reset_confirm,
    password_reset_done as django_password_reset_done)
from django.contrib import messages
from django.http import HttpResponseRedirect
from django.views.generic import (
    CreateView,
    FormView,
    UpdateView)
from brasilcomvc.common.views import AnonymousRequiredMixin, LoginRequiredMixin
from .forms import (
    EditNotificationsForm,
    DeleteUserForm,
    LoginForm,
    PasswordResetForm,
    SignupForm,
    UserAddressForm)

# coding: utf8
from __future__ import unicode_literals




class Signup(AnonymousRequiredMixin, CreateView):
    '''
    User Signup
    '''


    form_class = SignupForm