예제 #1
0
 def get(self, request, email_pk, verif_key, next=MM.POST_VERIFY_URL):
     try:
         email = EmailAddress.objects.get(pk=email_pk, verif_key=verif_key)
         if email.is_verified():
             raise email.AlreadyVerified()
         if not MM.ALLOW_VERIFICATION_OF_INACTIVE_ACCOUNTS and \
                 not email.user.is_active:
             raise email.InactiveAccount()
         email.remote_addr = request.META.get('REMOTE_ADDR')
         email.remote_host = request.META.get('REMOTE_HOST')
         email.verified_at = now()
         email.save()
         email_verified.send_robust(sender=email)
         site = get_site()
         d = build_context_dict(site, email)
         messages.success(request,
                          MM.EMAIL_VERIFIED_MESSAGE % d,
                          fail_silently=not MM.USE_MESSAGES)
     except EmailAddress.DoesNotExist:
         messages.error(request,
                        MM.INVALID_VERIFICATION_LINK_MESSAGE,
                        fail_silently=not MM.USE_MESSAGES)
     except email.InactiveAccount:
         messages.error(request,
                        MM.INACTIVE_ACCOUNT_MESSAGE,
                        fail_silently=not MM.USE_MESSAGES)
     except email.AlreadyVerified:
         """Only allow a single verification to prevent abuses, such as
         re-verifying on a deactivated account."""
         messages.error(request,
                        MM.EMAIL_ALREADY_VERIFIED_MESSAGE,
                        fail_silently=not MM.USE_MESSAGES)
     return redirect(next)
예제 #2
0
 def send_verification(self, request=None):
     """Send email verification link for this EmailAddress object.
     Raises smtplib.SMTPException, and NoRouteToHost.
     """
     html_template = get_template(MM.VERIFICATION_EMAIL_HTML_TEMPLATE)
     text_template = get_template(MM.VERIFICATION_EMAIL_TEXT_TEMPLATE)
     from multimail.util import get_site
     site = get_site(request)
     d = build_context_dict(site, self)
     if request:
         context = RequestContext(request, d)
     else:
         context = Context(d)
     msg = EmailMultiAlternatives(MM.VERIFICATION_EMAIL_SUBJECT % d,
         text_template.render(context),MM.FROM_EMAIL_ADDRESS,
         [self.email])
     msg.attach_alternative(html_template.render(context), 'text/html')
     msg.send(fail_silently=False)
     if MM.USE_MESSAGES:
         message = MM.VERIFICATION_LINK_SENT_MESSAGE % d
         if request is not None:
             messages.success(request, message,
                 fail_silently=not MM.USE_MESSAGES)
         else:
             try:
                 self.user.message_set.create(message=message)
             except AttributeError:
                 pass # user.message_set is deprecated and has been
예제 #3
0
 def test_get_site__configured(self):
     Site.objects.all().delete()
     Site(domain='testdomain', name='TestName', id=1).save()
     settings.SITE_ID = 1
     Site.objects.clear_cache()
     site = get_site()
     self.assertEqual(site.domain, 'testdomain')
예제 #4
0
 def test_get_site__MM_configs(self):
     MM.SITE_DOMAIN = 'testdomain'
     MM.SITE_NAME = 'TestName'
     site = get_site()
     self.assertEqual(site.domain, 'testdomain')
     MM.SITE_DOMAIN = None
     MM.SITE_NAME = None
예제 #5
0
 def test_get_site__configured(self):
     Site.objects.all().delete()
     Site(domain='testdomain', name='TestName', id=1).save()
     settings.SITE_ID = 1
     Site.objects.clear_cache()
     site = get_site()
     self.assertEqual(site.domain, 'testdomain')        
예제 #6
0
 def test_get_site__MM_configs(self):
     MM.SITE_DOMAIN = 'testdomain'
     MM.SITE_NAME = 'TestName'
     site = get_site()
     self.assertEqual(site.domain, 'testdomain')        
     MM.SITE_DOMAIN = None
     MM.SITE_NAME = None
예제 #7
0
 def send_verification(self, request=None):
     """Send email verification link for this EmailAddress object.
     Raises smtplib.SMTPException, and NoRouteToHost.
     """
     html_template = get_template(MM.VERIFICATION_EMAIL_HTML_TEMPLATE)
     text_template = get_template(MM.VERIFICATION_EMAIL_TEXT_TEMPLATE)
     from multimail.util import get_site
     site = get_site(request)
     d = build_context_dict(site, self)
     if request:
         context = RequestContext(request, d)
     else:
         context = Context(d)
     msg = EmailMultiAlternatives(MM.VERIFICATION_EMAIL_SUBJECT % d,
                                  text_template.render(context),
                                  MM.FROM_EMAIL_ADDRESS, [self.email])
     msg.attach_alternative(html_template.render(context), 'text/html')
     msg.send(fail_silently=False)
     if MM.USE_MESSAGES:
         message = MM.VERIFICATION_LINK_SENT_MESSAGE % d
         if request is not None:
             messages.success(request,
                              message,
                              fail_silently=not MM.USE_MESSAGES)
         else:
             try:
                 self.user.message_set.create(message=message)
             except AttributeError:
                 pass  # user.message_set is deprecated and has been
예제 #8
0
 def get(self, request, email_pk, verif_key, next=MM.POST_VERIFY_URL):
     try:
         email = EmailAddress.objects.get(pk=email_pk, verif_key=verif_key)
         if email.is_verified():
             raise email.AlreadyVerified()
         if not MM.ALLOW_VERIFICATION_OF_INACTIVE_ACCOUNTS and \
                 not email.user.is_active:
             raise email.InactiveAccount()
         email.remote_addr = request.META.get('REMOTE_ADDR')
         email.remote_host = request.META.get('REMOTE_HOST')
         email.verified_at = now()
         email.save()
         email_verified.send_robust(sender=email)
         site = get_site()
         d = build_context_dict(site, email)
         messages.success(request, MM.EMAIL_VERIFIED_MESSAGE % d,
             fail_silently=not MM.USE_MESSAGES)
     except EmailAddress.DoesNotExist:
         messages.error(request, MM.INVALID_VERIFICATION_LINK_MESSAGE,
             fail_silently=not MM.USE_MESSAGES)
     except email.InactiveAccount:
         messages.error(request, MM.INACTIVE_ACCOUNT_MESSAGE,
             fail_silently=not MM.USE_MESSAGES)
     except email.AlreadyVerified:
         """Only allow a single verification to prevent abuses, such as
         re-verifying on a deactivated account."""
         messages.error(request, MM.EMAIL_ALREADY_VERIFIED_MESSAGE,
             fail_silently=not MM.USE_MESSAGES)
     return redirect(next)
예제 #9
0
 def test_get_site__fallback(self):
     Site.objects.all().delete()
     Site.objects.clear_cache()
     site = get_site()
     self.assertEqual(site.domain, 'example.com')
예제 #10
0
 def test_get_site__fallback(self):
     Site.objects.all().delete()
     Site.objects.clear_cache()
     site = get_site()
     self.assertEqual(site.domain, 'example.com')