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)
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) if request: site = get_current_site(request) else: try: site = Site.objects.get_current() except (ImproperlyConfigured, Site.DoesNotExist): # This is not a real Site object in the database, just # something to use as a placeholder. site = Site(domain='www.example.com', name='Example', pk=0) 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: self.user.message_set.create(message=message)
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
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
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 = timezone.now() email.save() email_verified.send_robust(sender=email) site = Site.objects.get_current() 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)