# Path: confirm/models.py
# class UserConfirmationKey(ConfirmationKey, UserConfirmationMixin):
#     subject = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
#                                 related_name='confirmations')
# 
#     message_template = 'confirm/user_contact.txt'
#     message_subject = 'Confirm your %(addr_type)s on %(protocol)s://%(domain)s'
# 
#     def confirm(self):
#         if self.type == ConfirmationKey.TYPE_EMAIL:
#             self.subject.email_confirmed = True
# 
#             # confirm any servers that have the same contact data
#             self.subject.servers.email(self.subject.email).update(contact_verified=True)
#         elif self.type == ConfirmationKey.TYPE_JID:
#             self.subject.jid_confirmed = True
# 
#             # confirm any servers that have the same contact data
#             self.subject.servers.jid(self.subject.jid).update(contact_verified=True)
# 
#         self.subject.save()
# 
#     def get_absolute_url(self):
#         return reverse('confirm:user_contact', kwargs={'key': self.key})


from celery import shared_task
from django.contrib.auth import get_user_model
from confirm.models import UserConfirmationKey
# This file is part of django-xmpp-server-list
# (https://github.com/mathiasertl/django-xmpp-server-list)
#
# django-xmpp-server-list is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xmppllist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with django-xmpp-server-list.  If not, see <http://www.gnu.org/licenses/>.




UserModel = get_user_model()


@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()

# Path: confirm/models.py
# class UserConfirmationKey(ConfirmationKey, UserConfirmationMixin):
#     subject = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,
#                                 related_name='confirmations')
# 
#     message_template = 'confirm/user_contact.txt'
#     message_subject = 'Confirm your %(addr_type)s on %(protocol)s://%(domain)s'
# 
#     def confirm(self):
#         if self.type == ConfirmationKey.TYPE_EMAIL:
#             self.subject.email_confirmed = True
# 
#             # confirm any servers that have the same contact data
#             self.subject.servers.email(self.subject.email).update(contact_verified=True)
#         elif self.type == ConfirmationKey.TYPE_JID:
#             self.subject.jid_confirmed = True
# 
#             # confirm any servers that have the same contact data
#             self.subject.servers.jid(self.subject.jid).update(contact_verified=True)
# 
#         self.subject.save()
# 
#     def get_absolute_url(self):
#         return reverse('confirm:user_contact', kwargs={'key': self.key})


# Path: account/tasks.py
from celery import shared_task
from django.contrib.auth import get_user_model
from confirm.models import UserConfirmationKey

# This file is part of django-xmpp-server-list
# (https://github.com/mathiasertl/django-xmpp-server-list)
#
# django-xmpp-server-list is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# xmppllist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with django-xmpp-server-list.  If not, see <http://www.gnu.org/licenses/>.




UserModel = get_user_model()


@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)