コード例 #1
0
    def form_valid(self, form):
        from prologin.email import send_email
        from django.utils.encoding import force_bytes
        from django.utils.http import urlsafe_base64_encode
        from django.contrib.auth.tokens import default_token_generator

        email = form.cleaned_data['email']
        active_users = auth.get_user_model().objects.filter(
            email__iexact=email, is_active=True)
        for user in active_users:
            # Make sure that no email is sent to a user that actually has
            # a password marked as unusable
            if not user.has_usable_password() and not user.legacy_md5_password:
                continue
            uid = urlsafe_base64_encode(force_bytes(user.pk))
            token = default_token_generator.make_token(user)
            url = absolute_site_url(
                self.request,
                reverse('users:password_reset_confirm',
                        kwargs=dict(uidb64=uid, token=token)))
            send_email("users/mails/pswd_reset", user.email, {
                'user': user,
                'url': url
            })

        messages.success(
            self.request,
            _("You should receive an email at %(email)s in a few moments. "
              "Please follow the instructions to complete the password reset.")
            % {'email': email})
        return super().form_valid(form)
コード例 #2
0
def send_activation_email(user, request=None):
    from django.test import RequestFactory
    from prologin.email import send_email
    request = request or RequestFactory().generic(
        'get', '/', secure=settings.SITE_BASE_URL.startswith('https'))
    activation = users.models.UserActivation.objects.register(user)
    url = absolute_site_url(request,
                            reverse('users:activate', args=[activation.slug]))
    send_email("users/mails/activation", user.email, {
        'user': user,
        'url': url
    })
コード例 #3
0
    def form_valid(self, form):
        # school that will be kept (and updated if user did so)
        base_school = form.save(commit=False)

        # notice affected users by mail
        for contestant in self.contestants_to_merge:
            user = contestant.user
            send_email('schools/mails/merged', user.email, {
                'user': user,
                'old_school': contestant.school,
                'school': base_school,
            })

        with transaction.atomic():
            self.contestants_to_merge.update(school=self.get_object())
            self.schools_to_merge.delete()
            return super().form_valid(form)
コード例 #4
0
    def form_valid(self, form):
        instance, created = SubscriberEmail.objects.get_or_create(
            email=form.cleaned_data['email'])

        if created:
            messages.add_message(self.request, messages.SUCCESS,
                                 _('Subscription succeeded'))
            send_email(
                'gcc/mails/subscribe',
                instance.email,
                {'unsubscribe_url': instance.get_unsubscribe_url},
            )
        else:
            messages.add_message(
                self.request,
                messages.WARNING,
                _('Subscription failed: already subscribed'),
            )

        return super().form_valid(form)