# Path: user/views.py
# class ActivateAccount(View):
#     success_url = reverse_lazy('dj-auth:login')
#     template_name = 'user/user_activate.html'
# 
#     @method_decorator(never_cache)
#     def get(self, request, uidb64, token):
#         User = get_user_model()
#         try:
#             # urlsafe_base64_decode()
#             #     -> bytestring in Py3
#             uid = force_text(
#                 urlsafe_base64_decode(uidb64))
#             user = User.objects.get(pk=uid)
#         except (TypeError, ValueError,
#                 OverflowError, User.DoesNotExist):
#             user = None
#         if (user is not None
#                 and token_generator
#                 .check_token(user, token)):
#             user.is_active = True
#             user.save()
#             success(
#                 request,
#                 'User Activated! '
#                 'You may now login.')
#             return redirect(self.success_url)
#         else:
#             return TemplateResponse(
#                 request,
#                 self.template_name)
# 
# class CreateAccount(MailContextViewMixin, View):
#     form_class = UserCreationForm
#     success_url = reverse_lazy(
#         'dj-auth:create_done')
#     template_name = 'user/user_create.html'
# 
#     @method_decorator(csrf_protect)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': self.form_class()})
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(sensitive_post_parameters(
#         'password1', 'password2'))
#     def post(self, request):
#         bound_form = self.form_class(request.POST)
#         if bound_form.is_valid():
#             # not catching returned user
#             bound_form.save(
#                 **self.get_save_kwargs(request))
#             if bound_form.mail_sent:  # mail sent?
#                 return redirect(self.success_url)
#             else:
#                 errs = (
#                     bound_form.non_field_errors())
#                 for err in errs:
#                     error(request, err)
#                 return redirect(
#                     'dj-auth:resend_activation')
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': bound_form})
# 
# class DisableAccount(View):
#     success_url = settings.LOGIN_REDIRECT_URL
#     template_name = (
#         'user/user_confirm_delete.html')
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(login_required)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name)
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(login_required)
#     def post(self, request):
#         user = get_user(request)
#         user.set_unusable_password()
#         user.is_active = False
#         user.save()
#         logout(request)
#         return redirect(self.success_url)
# 
# class ProfileDetail(
#         ProfileGetObjectMixin, DetailView):
#     model = Profile
# 
# class ProfileUpdate(
#         ProfileGetObjectMixin, UpdateView):
#     fields = ('about',)
#     model = Profile
# 
# class PublicProfileDetail(DetailView):
#     model = Profile
# 
# class ResendActivationEmail(
#         MailContextViewMixin, View):
#     form_class = ResendActivationEmailForm
#     success_url = reverse_lazy('dj-auth:login')
#     template_name = 'user/resend_activation.html'
# 
#     @method_decorator(csrf_protect)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': self.form_class()})
# 
#     @method_decorator(csrf_protect)
#     def post(self, request):
#         bound_form = self.form_class(request.POST)
#         if bound_form.is_valid():
#             user = bound_form.save(
#                 **self.get_save_kwargs(request))
#             if (user is not None
#                     and not bound_form.mail_sent):
#                 errs = (
#                     bound_form.non_field_errors())
#                 for err in errs:
#                     error(request, err)
#                 if errs:
#                     bound_form.errors.pop(
#                         '__all__')
#                 return TemplateResponse(
#                     request,
#                     self.template_name,
#                     {'form': bound_form})
#         success(
#             request,
#             'Activation Email Sent!')
#         return redirect(self.success_url)


from django.conf.urls import include, url
from django.contrib.auth import \
    views as auth_views
from django.contrib.auth.forms import \
    AuthenticationForm
from django.core.urlresolvers import reverse_lazy
from django.views.generic import (
    RedirectView, TemplateView)
from .views import (
    ActivateAccount, CreateAccount,
    DisableAccount, ProfileDetail, ProfileUpdate,
    PublicProfileDetail, ResendActivationEmail)
            'user/password_reset_sent.html'},
        name='pw_reset_sent'),
    url(r'^reset/'
        r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
        r'(?P<token>[0-9A-Za-z]{1,13}'
        r'-[0-9A-Za-z]{1,20})/$',
        auth_views.password_reset_confirm,
        {'template_name':
            'user/password_reset_confirm.html',
         'post_reset_redirect': reverse_lazy(
            'dj-auth:pw_reset_complete')},
        name='pw_reset_confirm'),
    url(r'reset/done/$',
        auth_views.password_reset_complete,
        {'template_name':
            'user/password_reset_complete.html',
         'extra_context':
             {'form': AuthenticationForm}},
        name='pw_reset_complete'),
]

urlpatterns = [
    url(r'^$',
        RedirectView.as_view(
            pattern_name='dj-auth:login',
            permanent=False)),
    url(r'^activate/'
        r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
        r'(?P<token>[0-9A-Za-z]{1,13}'
        r'-[0-9A-Za-z]{1,20})/$',

# Path: user/views.py
# class ActivateAccount(View):
#     success_url = reverse_lazy('dj-auth:login')
#     template_name = 'user/user_activate.html'
# 
#     @method_decorator(never_cache)
#     def get(self, request, uidb64, token):
#         User = get_user_model()
#         try:
#             # urlsafe_base64_decode()
#             #     -> bytestring in Py3
#             uid = force_text(
#                 urlsafe_base64_decode(uidb64))
#             user = User.objects.get(pk=uid)
#         except (TypeError, ValueError,
#                 OverflowError, User.DoesNotExist):
#             user = None
#         if (user is not None
#                 and token_generator
#                 .check_token(user, token)):
#             user.is_active = True
#             user.save()
#             success(
#                 request,
#                 'User Activated! '
#                 'You may now login.')
#             return redirect(self.success_url)
#         else:
#             return TemplateResponse(
#                 request,
#                 self.template_name)
# 
# class CreateAccount(MailContextViewMixin, View):
#     form_class = UserCreationForm
#     success_url = reverse_lazy(
#         'dj-auth:create_done')
#     template_name = 'user/user_create.html'
# 
#     @method_decorator(csrf_protect)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': self.form_class()})
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(sensitive_post_parameters(
#         'password1', 'password2'))
#     def post(self, request):
#         bound_form = self.form_class(request.POST)
#         if bound_form.is_valid():
#             # not catching returned user
#             bound_form.save(
#                 **self.get_save_kwargs(request))
#             if bound_form.mail_sent:  # mail sent?
#                 return redirect(self.success_url)
#             else:
#                 errs = (
#                     bound_form.non_field_errors())
#                 for err in errs:
#                     error(request, err)
#                 return redirect(
#                     'dj-auth:resend_activation')
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': bound_form})
# 
# class DisableAccount(View):
#     success_url = settings.LOGIN_REDIRECT_URL
#     template_name = (
#         'user/user_confirm_delete.html')
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(login_required)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name)
# 
#     @method_decorator(csrf_protect)
#     @method_decorator(login_required)
#     def post(self, request):
#         user = get_user(request)
#         user.set_unusable_password()
#         user.is_active = False
#         user.save()
#         logout(request)
#         return redirect(self.success_url)
# 
# class ProfileDetail(
#         ProfileGetObjectMixin, DetailView):
#     model = Profile
# 
# class ProfileUpdate(
#         ProfileGetObjectMixin, UpdateView):
#     fields = ('about',)
#     model = Profile
# 
# class PublicProfileDetail(DetailView):
#     model = Profile
# 
# class ResendActivationEmail(
#         MailContextViewMixin, View):
#     form_class = ResendActivationEmailForm
#     success_url = reverse_lazy('dj-auth:login')
#     template_name = 'user/resend_activation.html'
# 
#     @method_decorator(csrf_protect)
#     def get(self, request):
#         return TemplateResponse(
#             request,
#             self.template_name,
#             {'form': self.form_class()})
# 
#     @method_decorator(csrf_protect)
#     def post(self, request):
#         bound_form = self.form_class(request.POST)
#         if bound_form.is_valid():
#             user = bound_form.save(
#                 **self.get_save_kwargs(request))
#             if (user is not None
#                     and not bound_form.mail_sent):
#                 errs = (
#                     bound_form.non_field_errors())
#                 for err in errs:
#                     error(request, err)
#                 if errs:
#                     bound_form.errors.pop(
#                         '__all__')
#                 return TemplateResponse(
#                     request,
#                     self.template_name,
#                     {'form': bound_form})
#         success(
#             request,
#             'Activation Email Sent!')
#         return redirect(self.success_url)


# Path: user/urls.py
from django.conf.urls import include, url
from django.contrib.auth import \
    views as auth_views
from django.contrib.auth.forms import \
    AuthenticationForm
from django.core.urlresolvers import reverse_lazy
from django.views.generic import (
    RedirectView, TemplateView)
from .views import (
    ActivateAccount, CreateAccount,
    DisableAccount, ProfileDetail, ProfileUpdate,
    PublicProfileDetail, ResendActivationEmail)

            'user/password_reset_sent.html'},
        name='pw_reset_sent'),
    url(r'^reset/'
        r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
        r'(?P<token>[0-9A-Za-z]{1,13}'
        r'-[0-9A-Za-z]{1,20})/$',
        auth_views.password_reset_confirm,
        {'template_name':
            'user/password_reset_confirm.html',
         'post_reset_redirect': reverse_lazy(
            'dj-auth:pw_reset_complete')},
        name='pw_reset_confirm'),
    url(r'reset/done/$',
        auth_views.password_reset_complete,
        {'template_name':
            'user/password_reset_complete.html',
         'extra_context':
             {'form': AuthenticationForm}},
        name='pw_reset_complete'),
]

urlpatterns = [
    url(r'^$',
        RedirectView.as_view(
            pattern_name='dj-auth:login',
            permanent=False)),
    url(r'^activate/'
        r'(?P<uidb64>[0-9A-Za-z_\-]+)/'
        r'(?P<token>[0-9A-Za-z]{1,13}'
        r'-[0-9A-Za-z]{1,20})/$',

        ActivateAccount.as_view(),