# Path: core/views.py
# class AnonymousRequiredMixin:
#     """Mixin to redirect authenticated users to a different page.
# 
#     Set the ``authenticated_url`` property of a view using this mixin to redirect authenticated users to
#     that url.
#     """
#     def get_authenticated_url(self):
#         return self.authenticated_url
# 
#     def dispatch(self, request, *args, **kwargs):
#         if request.user.is_authenticated:
#             return redirect(self.get_authenticated_url())
# 
#         return super().dispatch(request, *args, **kwargs)
# 
# Path: account/forms.py
# class PasswordChangeForm(auth_forms.PasswordChangeForm):
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.fields['new_password2'].label = _('Confirm')  # Shorten text to improve wrapping of label
# 
# Path: account/forms.py
# class PasswordResetForm(auth_forms.PasswordResetForm):
#     """Override the default form class to also send XMPP messages to JIDs."""
# 
#     email = forms.EmailField(label=_("JID or email"), max_length=254)
# 
#     def get_users(self, email):
#         """Override parent class so we also match the JID of users."""
# 
#         active_users = UserModel.objects.jid_or_email(email).filter(is_active=True)
#         return (u for u in active_users if u.has_usable_password())
# 
#     def send_mail(self, subject_template_name, email_template_name,
#                   context, from_email, to_email, html_email_template_name=None):
#         """Override so we can also send a message via XMPP.
# 
#         Note that we do not override the save() method, where we could generate an independent token,
#         but this would create a lot of additional code. Here we can just render the same message again.
#         """
# 
#         super().send_mail(subject_template_name, email_template_name,
#                           context, from_email, to_email, html_email_template_name)
# 
#         xmpp_template_name = 'account/password_reset_xmpp.txt'
#         message = loader.render_to_string(xmpp_template_name, context).strip()
#         default_xmpp_backend.send_chat_message(context['user'], message)
# 
# Path: account/forms.py
# class UserCreationForm(UserCreationForm):
#     class Meta:
#         model = UserModel
#         fields = ('username', 'email', 'jid',)
# 
#     def clean_username(self):
#         """Override to make the form compatible with custom user models."""
# 
#         # Since User.username is unique, this check is redundant,
#         # but it sets a nicer error message than the ORM. See #13147.
#         username = self.cleaned_data["username"]
#         try:
#             UserModel._default_manager.get(username=username)
#         except UserModel.DoesNotExist:
#             return username
#         raise forms.ValidationError(_('Username already exists.'))
# 
# Path: account/tasks.py
# @shared_task
# def send_email_confirmation(user_pk, host, is_secure=True):
#     """Send an email to confirm a users email address."""
# 
#     user = UserModel.objects.get(pk=user_pk)
#     UserConfirmationKey.objects.filter(subject=user, type=UserConfirmationKey.TYPE_EMAIL).delete()
#     key = UserConfirmationKey.objects.create(subject=user, type=UserConfirmationKey.TYPE_EMAIL)
#     key.send('https' if is_secure else 'http', host)
# 
# Path: account/tasks.py
# @shared_task
# def send_jid_confirmation(user_pk, host, is_secure=True):
#     """Send an XMPP message to confirm a users JID."""
# 
#     user = UserModel.objects.get(pk=user_pk)
#     UserConfirmationKey.objects.filter(subject=user, type=UserConfirmationKey.TYPE_JID).delete()
#     key = UserConfirmationKey.objects.create(subject=user, type=UserConfirmationKey.TYPE_JID)
#     key.send('https' if is_secure else 'http', host)


from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth import login
from django.contrib.auth import views as auth_views
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from core.views import AnonymousRequiredMixin
from .forms import PasswordChangeForm
from .forms import PasswordResetForm
from .forms import UserCreationForm
from .tasks import send_email_confirmation
from .tasks import send_jid_confirmation
        if not request.user.email_confirmed:
            self.send_email_confirmation(request.user)
        if not request.user.jid_confirmed:
            self.send_jid_confirmation(request.user)

        return super().get(request)


class PasswordChangeView(auth_views.PasswordChangeView):
    form_class = PasswordChangeForm
    success_url = reverse_lazy('account:index')
    template_name = 'account/password_change_form.html'

    def form_valid(self, form):
        response = super().form_valid(form)
        messages.success(self.request, _('Password was successfully updated.'))
        return response


class PasswordResetView(AnonymousRequiredMixin, auth_views.PasswordResetView):
    authenticated_url = reverse_lazy('account:index')
    form_class = PasswordResetForm
    template_name = 'account/password_reset_form.html'


class PasswordResetDoneView(AnonymousRequiredMixin, auth_views.PasswordResetDoneView):
    authenticated_url = reverse_lazy('account:index')
    template_name = 'account/password_reset_done.html'



# Path: core/views.py
# class AnonymousRequiredMixin:
#     """Mixin to redirect authenticated users to a different page.
# 
#     Set the ``authenticated_url`` property of a view using this mixin to redirect authenticated users to
#     that url.
#     """
#     def get_authenticated_url(self):
#         return self.authenticated_url
# 
#     def dispatch(self, request, *args, **kwargs):
#         if request.user.is_authenticated:
#             return redirect(self.get_authenticated_url())
# 
#         return super().dispatch(request, *args, **kwargs)
# 
# Path: account/forms.py
# class PasswordChangeForm(auth_forms.PasswordChangeForm):
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.fields['new_password2'].label = _('Confirm')  # Shorten text to improve wrapping of label
# 
# Path: account/forms.py
# class PasswordResetForm(auth_forms.PasswordResetForm):
#     """Override the default form class to also send XMPP messages to JIDs."""
# 
#     email = forms.EmailField(label=_("JID or email"), max_length=254)
# 
#     def get_users(self, email):
#         """Override parent class so we also match the JID of users."""
# 
#         active_users = UserModel.objects.jid_or_email(email).filter(is_active=True)
#         return (u for u in active_users if u.has_usable_password())
# 
#     def send_mail(self, subject_template_name, email_template_name,
#                   context, from_email, to_email, html_email_template_name=None):
#         """Override so we can also send a message via XMPP.
# 
#         Note that we do not override the save() method, where we could generate an independent token,
#         but this would create a lot of additional code. Here we can just render the same message again.
#         """
# 
#         super().send_mail(subject_template_name, email_template_name,
#                           context, from_email, to_email, html_email_template_name)
# 
#         xmpp_template_name = 'account/password_reset_xmpp.txt'
#         message = loader.render_to_string(xmpp_template_name, context).strip()
#         default_xmpp_backend.send_chat_message(context['user'], message)
# 
# Path: account/forms.py
# class UserCreationForm(UserCreationForm):
#     class Meta:
#         model = UserModel
#         fields = ('username', 'email', 'jid',)
# 
#     def clean_username(self):
#         """Override to make the form compatible with custom user models."""
# 
#         # Since User.username is unique, this check is redundant,
#         # but it sets a nicer error message than the ORM. See #13147.
#         username = self.cleaned_data["username"]
#         try:
#             UserModel._default_manager.get(username=username)
#         except UserModel.DoesNotExist:
#             return username
#         raise forms.ValidationError(_('Username already exists.'))
# 
# Path: account/tasks.py
# @shared_task
# def send_email_confirmation(user_pk, host, is_secure=True):
#     """Send an email to confirm a users email address."""
# 
#     user = UserModel.objects.get(pk=user_pk)
#     UserConfirmationKey.objects.filter(subject=user, type=UserConfirmationKey.TYPE_EMAIL).delete()
#     key = UserConfirmationKey.objects.create(subject=user, type=UserConfirmationKey.TYPE_EMAIL)
#     key.send('https' if is_secure else 'http', host)
# 
# Path: account/tasks.py
# @shared_task
# def send_jid_confirmation(user_pk, host, is_secure=True):
#     """Send an XMPP message to confirm a users JID."""
# 
#     user = UserModel.objects.get(pk=user_pk)
#     UserConfirmationKey.objects.filter(subject=user, type=UserConfirmationKey.TYPE_JID).delete()
#     key = UserConfirmationKey.objects.create(subject=user, type=UserConfirmationKey.TYPE_JID)
#     key.send('https' if is_secure else 'http', host)


# Path: account/views.py
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth import login
from django.contrib.auth import views as auth_views
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import TemplateView
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from core.views import AnonymousRequiredMixin
from .forms import PasswordChangeForm
from .forms import PasswordResetForm
from .forms import UserCreationForm
from .tasks import send_email_confirmation
from .tasks import send_jid_confirmation

        if not request.user.email_confirmed:
            self.send_email_confirmation(request.user)
        if not request.user.jid_confirmed:
            self.send_jid_confirmation(request.user)

        return super().get(request)


class PasswordChangeView(auth_views.PasswordChangeView):
    form_class = PasswordChangeForm
    success_url = reverse_lazy('account:index')
    template_name = 'account/password_change_form.html'

    def form_valid(self, form):
        response = super().form_valid(form)
        messages.success(self.request, _('Password was successfully updated.'))
        return response


class PasswordResetView(AnonymousRequiredMixin, auth_views.PasswordResetView):
    authenticated_url = reverse_lazy('account:index')
    form_class = PasswordResetForm
    template_name = 'account/password_reset_form.html'


class PasswordResetDoneView(AnonymousRequiredMixin, auth_views.PasswordResetDoneView):
    authenticated_url = reverse_lazy('account:index')
    template_name = 'account/password_reset_done.html'



class PasswordResetConfirmView(AnonymousRequiredMixin, auth_views.PasswordResetConfirmView):