# Path: brasilcomvc/accounts/views.py
# class DeleteUser(LoginRequiredMixin, FormView):
# 
#     form_class = DeleteUserForm
#     template_name = 'accounts/delete-user.html'
# 
#     def get_form_kwargs(self):
#         kwargs = super(DeleteUser, self).get_form_kwargs()
#         kwargs['user'] = self.request.user
#         return kwargs
# 
#     def form_valid(self, form):
#         email = self.request.user.email
# 
#         # Delete user and logout (clean session)
#         self.request.user.delete()
#         logout_user(self.request)
# 
#         # Put deleted_email into session for feedback form consumption
#         self.request.session['deleted_email'] = email
#         self.request.session['feedback_success_message'] = (
#             'Sua conta foi excluída. Até logo! :(')
#         return HttpResponseRedirect('{}?next={}'.format(
#             reverse('feedback:create'), reverse('accounts:login')))
# 
# def login(request, *args, **kwargs):
#     if request.user and request.user.is_authenticated():
#         return HttpResponseRedirect(reverse('accounts:edit_dashboard'))
#     return auth_login(
#         request,
#         authentication_form=LoginForm,
#         template_name='accounts/login.html',
#     )
# 
# def logout(request):
#     """
#     Logout user and redirect back to login page
#     """
#     logout_user(request)
#     return HttpResponseRedirect(reverse('accounts:login'))
# 
# def password_reset(request):
#     return django_password_reset(
#         request,
#         template_name='accounts/password_reset.html',
#         password_reset_form=PasswordResetForm,
#         post_reset_redirect=reverse('accounts:password_reset_sent'))
# 
# def password_reset_confirm(request, **kwargs):
#     return django_password_reset_confirm(
#         request,
#         template_name='accounts/password_reset_confirm.html',
#         post_reset_redirect=reverse('accounts:login'),
#         **kwargs)
# 
# def password_reset_sent(request):
#     return django_password_reset_done(
#         request,
#         template_name='accounts/password_reset_sent.html')
# 
# class EditNotifications(BaseEditUser, UpdateView):
# 
#     form_class = EditNotificationsForm
#     title = 'Notificações'
#     url_pattern = 'accounts:edit_notifications'
# 
# class EditPersonalInfo(BaseEditUser, UpdateView):
# 
#     fields = ('full_name', 'username', 'email', 'picture',)
#     title = 'Informações Pessoais'
#     url_pattern = 'accounts:edit_personal_info'
# 
# class EditProfessionalInfo(BaseEditUser, UpdateView):
# 
#     fields = ('job_title', 'bio',)
#     title = 'Informações Profissionais'
#     url_pattern = 'accounts:edit_professional_info'
# 
# class EditSecuritySettings(BaseEditUser, UpdateView):
# 
#     form_class = PasswordChangeForm
#     success_message = 'Configurações de segurança atualizadas com sucesso!'
#     template_name = 'accounts/edit_security_settings.html'
#     title = 'Segurança'
#     url_pattern = 'accounts:edit_security_settings'
# 
#     def get_form_kwargs(self):
#         kwargs = super(EditSecuritySettings, self).get_form_kwargs()
#         kwargs['user'] = kwargs.pop('instance')
#         return kwargs
# 
# class EditUserAddress(BaseEditUser, UpdateView):
# 
#     form_class = UserAddressForm
#     title = 'Editar Endereço'
#     url_pattern = 'accounts:edit_user_address'
# 
#     def get_object(self):
#         # If the user already has an address, make it the edition target
#         return getattr(self.request.user, 'address', None)
# 
#     def form_valid(self, form):
#         address = form.save(commit=False)
#         address.user = self.request.user
#         address.save()
#         return super(EditUserAddress, self).form_valid(form)
# 
# class Signup(AnonymousRequiredMixin, CreateView):
#     '''
#     User Signup
#     '''
# 
#     form_class = SignupForm
#     success_url = reverse_lazy('accounts:edit_dashboard')
#     template_name = 'accounts/signup.html'
# 
#     def form_valid(self, form):
#         response = super(Signup, self).form_valid(form)
# 
#         # log user in
#         user = authenticate(email=form.cleaned_data['email'],
#                             password=form.cleaned_data['password'])
#         login_user(self.request, user)
# 
#         # Send welcome email upon signup
#         user.send_welcome_email()
# 
#         # Display a welcome message
#         messages.info(
#             self.request,
#             'Parabéns! Você agora está cadastrado e já pode buscar projetos '
#             'para participar. Bem vindo e mãos à obra!')
# 
#         return response


from django.conf.urls import url
from django.views.generic import RedirectView
from .views import (
    DeleteUser,
    login,
    logout,
    password_reset,
    password_reset_confirm,
    password_reset_sent,
    EditNotifications,
    EditPersonalInfo,
    EditProfessionalInfo,
    EditSecuritySettings,
    EditUserAddress,
    Signup,
)



urlpatterns = (
    # User Login
    url(r'^login/$',
        login, name='login'),

    # User Logout
    url(r'^logout/$',
        logout, name='logout'),

    # Password Reset
    url(r'^esqueci-senha/$',
        password_reset, name='password_reset'),

    # Password Reset Sent
    url(r'^esqueci-senha/enviado$',
        password_reset_sent, name='password_reset_sent'),

    # Password Reset Confirm
    url(r'^esqueci-senha/redefinir/(?P<uidb64>[^-]+)-(?P<token>[^$]+)$',
        password_reset_confirm, name='password_reset_confirm'),

    # User Signup
    url(r'^cadastro/$',

# Path: brasilcomvc/accounts/views.py
# class DeleteUser(LoginRequiredMixin, FormView):
# 
#     form_class = DeleteUserForm
#     template_name = 'accounts/delete-user.html'
# 
#     def get_form_kwargs(self):
#         kwargs = super(DeleteUser, self).get_form_kwargs()
#         kwargs['user'] = self.request.user
#         return kwargs
# 
#     def form_valid(self, form):
#         email = self.request.user.email
# 
#         # Delete user and logout (clean session)
#         self.request.user.delete()
#         logout_user(self.request)
# 
#         # Put deleted_email into session for feedback form consumption
#         self.request.session['deleted_email'] = email
#         self.request.session['feedback_success_message'] = (
#             'Sua conta foi excluída. Até logo! :(')
#         return HttpResponseRedirect('{}?next={}'.format(
#             reverse('feedback:create'), reverse('accounts:login')))
# 
# def login(request, *args, **kwargs):
#     if request.user and request.user.is_authenticated():
#         return HttpResponseRedirect(reverse('accounts:edit_dashboard'))
#     return auth_login(
#         request,
#         authentication_form=LoginForm,
#         template_name='accounts/login.html',
#     )
# 
# def logout(request):
#     """
#     Logout user and redirect back to login page
#     """
#     logout_user(request)
#     return HttpResponseRedirect(reverse('accounts:login'))
# 
# def password_reset(request):
#     return django_password_reset(
#         request,
#         template_name='accounts/password_reset.html',
#         password_reset_form=PasswordResetForm,
#         post_reset_redirect=reverse('accounts:password_reset_sent'))
# 
# def password_reset_confirm(request, **kwargs):
#     return django_password_reset_confirm(
#         request,
#         template_name='accounts/password_reset_confirm.html',
#         post_reset_redirect=reverse('accounts:login'),
#         **kwargs)
# 
# def password_reset_sent(request):
#     return django_password_reset_done(
#         request,
#         template_name='accounts/password_reset_sent.html')
# 
# class EditNotifications(BaseEditUser, UpdateView):
# 
#     form_class = EditNotificationsForm
#     title = 'Notificações'
#     url_pattern = 'accounts:edit_notifications'
# 
# class EditPersonalInfo(BaseEditUser, UpdateView):
# 
#     fields = ('full_name', 'username', 'email', 'picture',)
#     title = 'Informações Pessoais'
#     url_pattern = 'accounts:edit_personal_info'
# 
# class EditProfessionalInfo(BaseEditUser, UpdateView):
# 
#     fields = ('job_title', 'bio',)
#     title = 'Informações Profissionais'
#     url_pattern = 'accounts:edit_professional_info'
# 
# class EditSecuritySettings(BaseEditUser, UpdateView):
# 
#     form_class = PasswordChangeForm
#     success_message = 'Configurações de segurança atualizadas com sucesso!'
#     template_name = 'accounts/edit_security_settings.html'
#     title = 'Segurança'
#     url_pattern = 'accounts:edit_security_settings'
# 
#     def get_form_kwargs(self):
#         kwargs = super(EditSecuritySettings, self).get_form_kwargs()
#         kwargs['user'] = kwargs.pop('instance')
#         return kwargs
# 
# class EditUserAddress(BaseEditUser, UpdateView):
# 
#     form_class = UserAddressForm
#     title = 'Editar Endereço'
#     url_pattern = 'accounts:edit_user_address'
# 
#     def get_object(self):
#         # If the user already has an address, make it the edition target
#         return getattr(self.request.user, 'address', None)
# 
#     def form_valid(self, form):
#         address = form.save(commit=False)
#         address.user = self.request.user
#         address.save()
#         return super(EditUserAddress, self).form_valid(form)
# 
# class Signup(AnonymousRequiredMixin, CreateView):
#     '''
#     User Signup
#     '''
# 
#     form_class = SignupForm
#     success_url = reverse_lazy('accounts:edit_dashboard')
#     template_name = 'accounts/signup.html'
# 
#     def form_valid(self, form):
#         response = super(Signup, self).form_valid(form)
# 
#         # log user in
#         user = authenticate(email=form.cleaned_data['email'],
#                             password=form.cleaned_data['password'])
#         login_user(self.request, user)
# 
#         # Send welcome email upon signup
#         user.send_welcome_email()
# 
#         # Display a welcome message
#         messages.info(
#             self.request,
#             'Parabéns! Você agora está cadastrado e já pode buscar projetos '
#             'para participar. Bem vindo e mãos à obra!')
# 
#         return response


# Path: brasilcomvc/accounts/urls.py
from django.conf.urls import url
from django.views.generic import RedirectView
from .views import (
    DeleteUser,
    login,
    logout,
    password_reset,
    password_reset_confirm,
    password_reset_sent,
    EditNotifications,
    EditPersonalInfo,
    EditProfessionalInfo,
    EditSecuritySettings,
    EditUserAddress,
    Signup,
)




urlpatterns = (
    # User Login
    url(r'^login/$',
        login, name='login'),

    # User Logout
    url(r'^logout/$',
        logout, name='logout'),

    # Password Reset
    url(r'^esqueci-senha/$',
        password_reset, name='password_reset'),

    # Password Reset Sent
    url(r'^esqueci-senha/enviado$',
        password_reset_sent, name='password_reset_sent'),

    # Password Reset Confirm
    url(r'^esqueci-senha/redefinir/(?P<uidb64>[^-]+)-(?P<token>[^$]+)$',
        password_reset_confirm, name='password_reset_confirm'),

    # User Signup
    url(r'^cadastro/$',

        Signup.as_view(), name='signup'),