示例#1
0
 def save(self):
     """ Saves nothing but sends a warning email to old email,
         and sends a confirmation link to the new email address.
     """
     old_email = self.instance.email
     new_email = self.cleaned_data['email']
     url = create_unique_url({
         'action': 'email_update',
         'pk': self.instance.pk,
         'email': new_email,
     })
     context = Context({
         'site_name': settings.SITE_NAME,
         'url': url,
         'user': self.instance,
         'email': new_email,
     })
     subject = _("You changed your email address")
     for old_new in ['old', 'new']:
         message = get_template('email/%s_email_update.txt' % old_new)
         html_message = get_template('email/%s_email_update.html' % old_new)
         send_mail(subject,
                   message.render(context),
                   settings.DEFAULT_FROM_EMAIL,
                   recipient_list=[{
                       'old': old_email,
                       'new': new_email
                   }[old_new]],
                   html_message=html_message.render(context),
                   fail_silently=False)
     return self.instance
示例#2
0
    def post(self, request, *args, **kwargs):
        config = SiteConfiguration.get_solo()
        email_to_verify = value_without_invalid_marker(request.user.email)
        url = create_unique_url({
            'action': 'email_update',
            'v': True,
            'pk': request.user.pk,
            'email': email_to_verify,
        })
        context = {
            'site_name': config.site_name,
            'url': url,
            'user': request.user,
        }
        subject = _("[Pasporta Servo] Is this your email address?")
        email_template_text = get_template('email/system-email_verify.txt')
        email_template_html = get_template('email/system-email_verify.html')
        send_mail(
            subject,
            email_template_text.render(context),
            settings.DEFAULT_FROM_EMAIL,
            recipient_list=[email_to_verify],
            html_message=email_template_html.render(context),
            fail_silently=False)

        if request.is_ajax():
            return JsonResponse({'success': 'verification-requested'})
        else:
            return TemplateResponse(request, self.template_name)
示例#3
0
    def post(self, request, *args, **kwargs):
        config = SiteConfiguration.get_solo()
        email_to_verify = value_without_invalid_marker(request.user.email)
        url, token = create_unique_url({
            'action': 'email_update',
            'v': True,
            'pk': request.user.pk,
            'email': email_to_verify,
        })
        context = {
            'site_name': config.site_name,
            'ENV': settings.ENVIRONMENT,
            'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL,
            'url': url,
            'url_first': url[:url.rindex('/') + 1],
            'url_second': token,
            'user': request.user,
        }
        email_template_subject = get_template(
            'email/system-email_verify_subject.txt')
        email_template_text = get_template('email/system-email_verify.txt')
        email_template_html = get_template('email/system-email_verify.html')
        send_mail(
            ''.join(email_template_subject.render(
                context).splitlines()),  # no newlines allowed in subject.
            email_template_text.render(context),
            settings.DEFAULT_FROM_EMAIL,
            recipient_list=[email_to_verify],
            html_message=email_template_html.render(context),
            fail_silently=False)

        if request.is_ajax():
            return JsonResponse({'success': 'verification-requested'})
        else:
            return TemplateResponse(request, self.template_name)
示例#4
0
 def save(self):
     """ Saves nothing but sends a warning email to old email,
         and sends a confirmation link to the new email address.
     """
     old_email = self.instance.email
     new_email = self.cleaned_data['email']
     url = create_unique_url({
         'action': 'email_update',
         'pk': self.instance.pk,
         'email': new_email,
     })
     context = Context({
         'site_name': settings.SITE_NAME,
         'url': url,
         'user': self.instance,
         'email': new_email,
     })
     subject = _("You changed your email address")
     for old_new in ['old', 'new']:
         message = get_template('email/%s_email_update.txt' % old_new)
         html_message = get_template('email/%s_email_update.html' % old_new)
         send_mail(
             subject,
             message.render(context),
             settings.DEFAULT_FROM_EMAIL,
             recipient_list=[{'old': old_email, 'new': new_email}[old_new]],
             html_message=html_message.render(context),
             fail_silently=False)
     return self.instance
示例#5
0
    def save(self, commit=True):
        """
        Saves nothing but sends a warning email to old email address,
        and sends a confirmation link to the new email address.
        """
        config = SiteConfiguration.get_solo()
        old_email = self.previous_email
        new_email = self.cleaned_data['email']
        if old_email == new_email:
            return self.instance

        url, token = create_unique_url({
            'action': 'email_update',
            'v': False,
            'pk': self.instance.pk,
            'email': new_email,
        })
        context = {
            'site_name': config.site_name,
            'ENV': settings.ENVIRONMENT,
            'subject_prefix': settings.EMAIL_SUBJECT_PREFIX_FULL,
            'url': url,
            'url_first': url[:url.rindex('/') + 1],
            'url_second': token,
            'user': self.instance,
            'email': new_email,
        }
        for old_new in ['old', 'new']:
            email_template_subject = get_template(
                f'email/{old_new}_email_subject.txt')
            email_template_text = get_template(
                f'email/{old_new}_email_update.txt')
            email_template_html = get_template(
                f'email/{old_new}_email_update.html')
            send_mail(
                ''.join(email_template_subject.render(
                    context).splitlines()),  # no newlines allowed in subject.
                email_template_text.render(context),
                settings.DEFAULT_FROM_EMAIL,
                recipient_list=[{
                    'old': old_email,
                    'new': new_email
                }[old_new]],
                html_message=email_template_html.render(context),
                fail_silently=False)

        return self.instance
示例#6
0
 def test_create_unique_url(self):
     test_data = [
         ("{aaa}", 'InthYWF9Ig'),
         ("/CCC/", 'Ii9DQ0MvIg'),
         ("", 'IiI'),
         ({'name': "A. User", 'profession': "Tester"}, 'eyJuYW1lIjoiQS4gVXNlciIsInByb2Zlc3Npb24iOiJUZXN0ZXIifQ'),
         ({}, 'e30'),
         # A large payload is gzipped and then base64-encoded.
         ("[Quite a long content over here]"*3, '.eJxTig4szSxJVUhUyMnPS1dIzs8rSc0rUcgvSy1SyEgtSo2lVF4JAN38I6k'),
     ]
     for payload, token_prefix in test_data:
         with self.subTest(payload=payload):
             result = create_unique_url(payload=payload, salt="bbbb")
             self.assertIs(type(result), tuple)
             self.assertEqual(len(result), 2)
             self.assertStartsWith(result[0], '/ligilo/{}.'.format(token_prefix))
             self.assertStartsWith(result[1], '{}.'.format(token_prefix))
             self.assertEqual(result[1].count('.'), 3 if token_prefix.startswith('.') else 2)
示例#7
0
    def save(self):
        """
        Saves nothing but sends a warning email to old email address,
        and sends a confirmation link to the new email address.
        """
        config = SiteConfiguration.get_solo()
        old_email = self.previous_email
        new_email = self.cleaned_data['email']
        if old_email == new_email:
            return self.instance

        url = create_unique_url({
            'action': 'email_update',
            'v': False,
            'pk': self.instance.pk,
            'email': new_email,
        })
        context = {
            'site_name': config.site_name,
            'url': url,
            'user': self.instance,
            'email': new_email,
        }
        subject = _("[Pasporta Servo] Change of email address")
        for old_new in ['old', 'new']:
            email_template_text = get_template(
                'email/{type}_email_update.txt'.format(type=old_new))
            email_template_html = get_template(
                'email/{type}_email_update.html'.format(type=old_new))
            send_mail(subject,
                      email_template_text.render(context),
                      settings.DEFAULT_FROM_EMAIL,
                      recipient_list=[{
                          'old': old_email,
                          'new': new_email
                      }[old_new]],
                      html_message=email_template_html.render(context),
                      fail_silently=False)

        return self.instance
示例#8
0
    def save(self):
        """
        Saves nothing but sends a warning email to old email address,
        and sends a confirmation link to the new email address.
        """
        config = SiteConfiguration.get_solo()
        old_email = self.previous_email
        new_email = self.cleaned_data['email']
        if old_email == new_email:
            return self.instance

        url = create_unique_url({
            'action': 'email_update',
            'v': False,
            'pk': self.instance.pk,
            'email': new_email,
        })
        context = {
            'site_name': config.site_name,
            'url': url,
            'user': self.instance,
            'email': new_email,
        }
        subject = _("[Pasporta Servo] Change of email address")
        for old_new in ['old', 'new']:
            email_template_text = get_template('email/{type}_email_update.txt'.format(type=old_new))
            email_template_html = get_template('email/{type}_email_update.html'.format(type=old_new))
            send_mail(
                subject,
                email_template_text.render(context),
                settings.DEFAULT_FROM_EMAIL,
                recipient_list=[{'old': old_email, 'new': new_email}[old_new]],
                html_message=email_template_html.render(context),
                fail_silently=False)

        return self.instance
示例#9
0
 def get_url(self, place, action):
     return create_unique_url({"place": place.pk, "action": action})
示例#10
0
 def get_url(self, place, action):
     return create_unique_url({'place': place.pk, 'action': action})
示例#11
0
 def get_url(self, place, action):
     return create_unique_url({'place': place.pk, 'action': action})