示例#1
0
def delete_account(request):
    if request.method == "POST":
        try:
            email = emails["account_deleted"]
            send_mail(
                email["subject"],
                email["body"] % request.user,
                email["from"],
                email["to"],
            )
            request.user.alerts.all().delete()
            request.user.docket_alerts.all().delete()
            request.user.favorites.all().delete()
            request.user.scotus_maps.all().update(deleted=True)
            convert_to_stub_account(request.user)
            logout(request)
            update_mailchimp.delay(request.user.email, "unsubscribed")

        except Exception as e:
            logger.critical("User was unable to delete account. %s" % e)

        return HttpResponseRedirect(reverse("delete_profile_done"))

    non_deleted_map_count = request.user.scotus_maps.filter(
        deleted=False).count()
    return render(
        request,
        "profile/delete.html",
        {
            "non_deleted_map_count": non_deleted_map_count,
            "private": True
        },
    )
示例#2
0
def delete_account(request: AuthenticatedHttpRequest) -> HttpResponse:
    if request.method == "POST":
        email: EmailType = emails["account_deleted"]
        send_mail(
            email["subject"],
            email["body"] % request.user,
            email["from_email"],
            email["to"],
        )
        request.user.alerts.all().delete()
        request.user.docket_alerts.all().delete()
        request.user.favorites.all().delete()
        request.user.user_tags.all().delete()
        request.user.monthly_donations.all().update(enabled=False)
        request.user.scotus_maps.all().update(deleted=True)
        user = convert_to_stub_account(request.user)
        update_mailchimp.delay(request.user.email, "unsubscribed")
        update_session_auth_hash(request, user)
        logout(request)
        return HttpResponseRedirect(reverse("delete_profile_done"))

    non_deleted_map_count = request.user.scotus_maps.filter(
        deleted=False).count()
    return render(
        request,
        "profile/delete.html",
        {
            "non_deleted_map_count": non_deleted_map_count,
            "private": True
        },
    )
示例#3
0
def view_settings(request):
    old_email = request.user.email  # this line has to be at the top to work.
    old_wants_newsletter = request.user.profile.wants_newsletter
    user = request.user
    up = user.profile
    user_form = UserForm(request.POST or None, instance=user)
    profile_form = ProfileForm(request.POST or None, instance=up)
    if profile_form.is_valid() and user_form.is_valid():
        user_cd = user_form.cleaned_data
        profile_cd = profile_form.cleaned_data
        new_email = user_cd['email']
        changed_email = old_email != new_email
        if changed_email:
            # Email was changed.
            up.activation_key = sha1_activation_key(user.username)
            up.key_expires = now() + timedelta(5)
            up.email_confirmed = False

            # Unsubscribe the old address in mailchimp (we'll
            # resubscribe it when they confirm it later).
            update_mailchimp.delay(old_email, 'unsubscribed')

            # Send the email.
            email = emails['email_changed_successfully']
            send_mail(
                email['subject'],
                email['body'] % (user.username, up.activation_key),
                email['from'],
                [new_email],
            )

            msg = message_dict['email_changed_successfully']
            messages.add_message(request, msg['level'], msg['message'])
            logout(request)
        else:
            # if the email wasn't changed, simply inform of success.
            msg = message_dict['settings_changed_successfully']
            messages.add_message(request, msg['level'], msg['message'])

        new_wants_newsletter = profile_cd['wants_newsletter']
        if old_wants_newsletter != new_wants_newsletter:
            if new_wants_newsletter is True and not changed_email:
                # They just subscribed. If they didn't *also* update their
                # email address, subscribe them.
                subscribe_to_mailchimp.delay(new_email)
            elif new_wants_newsletter is False:
                # They just unsubscribed
                update_mailchimp.delay(new_email, 'unsubscribed')

        # New email address and changes above are saved here.
        profile_form.save()
        user_form.save()

        return HttpResponseRedirect(reverse('view_settings'))
    return render(request, 'profile/settings.html', {
        'profile_form': profile_form,
        'user_form': user_form,
        'private': True
    })
示例#4
0
def delete_account(request):
    if request.method == 'POST':
        try:
            email = emails['account_deleted']
            send_mail(email['subject'], email['body'] % request.user,
                      email['from'], email['to'])
            request.user.alerts.all().delete()
            request.user.favorites.all().delete()
            request.user.scotus_maps.all().update(deleted=True)
            convert_to_stub_account(request.user)
            logout(request)
            update_mailchimp.delay(request.user.email, 'unsubscribed')

        except Exception as e:
            logger.critical("User was unable to delete account. %s" % e)

        return HttpResponseRedirect(reverse('delete_profile_done'))

    non_deleted_map_count = request.user.scotus_maps.filter(deleted=False).count()
    return render(request, 'profile/delete.html', {
        'non_deleted_map_count': non_deleted_map_count,
        'private': True
    })
示例#5
0
def delete_account(request):
    if request.method == 'POST':
        try:
            email = emails['account_deleted']
            send_mail(email['subject'], email['body'] % request.user,
                      email['from'], email['to'])
            request.user.alerts.all().delete()
            request.user.favorites.all().delete()
            request.user.scotus_maps.all().update(deleted=True)
            convert_to_stub_account(request.user)
            logout(request)
            update_mailchimp.delay(request.user.email, 'unsubscribed')

        except Exception as e:
            logger.critical("User was unable to delete account. %s" % e)

        return HttpResponseRedirect(reverse('delete_profile_done'))

    non_deleted_map_count = request.user.scotus_maps.filter(deleted=False).count()
    return render(request, 'profile/delete.html', {
        'non_deleted_map_count': non_deleted_map_count,
        'private': True
    })
示例#6
0
def view_settings(request):
    old_email = request.user.email  # this line has to be at the top to work.
    old_wants_newsletter = request.user.profile.wants_newsletter
    user = request.user
    up = user.profile
    user_form = UserForm(request.POST or None, instance=user)
    profile_form = ProfileForm(request.POST or None, instance=up)
    if profile_form.is_valid() and user_form.is_valid():
        user_cd = user_form.cleaned_data
        profile_cd = profile_form.cleaned_data
        new_email = user_cd["email"]
        changed_email = old_email != new_email
        if changed_email:
            # Email was changed.
            up.activation_key = sha1_activation_key(user.username)
            up.key_expires = now() + timedelta(5)
            up.email_confirmed = False

            # Unsubscribe the old address in mailchimp (we'll
            # resubscribe it when they confirm it later).
            update_mailchimp.delay(old_email, "unsubscribed")

            # Send an email to the new and old addresses. New for verification;
            # old for notification of the change.
            email = emails["email_changed_successfully"]
            send_mail(
                email["subject"],
                email["body"] % (user.username, up.activation_key),
                email["from"],
                [new_email],
            )
            email = emails["notify_old_address"]
            send_mail(
                email["subject"],
                email["body"] % (user.username, old_email, new_email),
                email["from"],
                [old_email],
            )
            msg = message_dict["email_changed_successfully"]
            messages.add_message(request, msg["level"], msg["message"])
            logout(request)
        else:
            # if the email wasn't changed, simply inform of success.
            msg = message_dict["settings_changed_successfully"]
            messages.add_message(request, msg["level"], msg["message"])

        new_wants_newsletter = profile_cd["wants_newsletter"]
        if old_wants_newsletter != new_wants_newsletter:
            if new_wants_newsletter is True and not changed_email:
                # They just subscribed. If they didn't *also* update their
                # email address, subscribe them.
                subscribe_to_mailchimp.delay(new_email)
            elif new_wants_newsletter is False:
                # They just unsubscribed
                update_mailchimp.delay(new_email, "unsubscribed")

        # New email address and changes above are saved here.
        profile_form.save()
        user_form.save()

        return HttpResponseRedirect(reverse("view_settings"))
    return render(
        request,
        "profile/settings.html",
        {
            "profile_form": profile_form,
            "user_form": user_form,
            "private": True,
        },
    )
示例#7
0
def view_settings(request):
    old_email = request.user.email  # this line has to be at the top to work.
    old_wants_newsletter = request.user.profile.wants_newsletter
    user = request.user
    up = user.profile
    user_form = UserForm(request.POST or None, instance=user)
    profile_form = ProfileForm(request.POST or None, instance=up)
    if profile_form.is_valid() and user_form.is_valid():
        user_cd = user_form.cleaned_data
        profile_cd = profile_form.cleaned_data
        new_email = user_cd['email']
        changed_email = old_email != new_email
        if changed_email:
            # Email was changed.

            # Build the activation key for the new account
            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
            up.activation_key = hashlib.sha1(salt + user.username).hexdigest()
            up.key_expires = now() + timedelta(5)
            up.email_confirmed = False

            # Unsubscribe the old address in mailchimp (we'll
            # resubscribe it when they confirm it later).
            update_mailchimp.delay(old_email, 'unsubscribed')

            # Send the email.
            email = emails['email_changed_successfully']
            send_mail(
                email['subject'],
                email['body'] % (user.username, up.activation_key),
                email['from'],
                [new_email],
            )

            msg = message_dict['email_changed_successfully']
            messages.add_message(request, msg['level'], msg['message'])
            logout(request)
        else:
            # if the email wasn't changed, simply inform of success.
            msg = message_dict['settings_changed_successfully']
            messages.add_message(request, msg['level'], msg['message'])

        new_wants_newsletter = profile_cd['wants_newsletter']
        if old_wants_newsletter != new_wants_newsletter:
            if new_wants_newsletter is True and not changed_email:
                # They just subscribed. If they didn't *also* update their
                # email address, subscribe them.
                subscribe_to_mailchimp.delay(new_email)
            elif new_wants_newsletter is False:
                # They just unsubscribed
                update_mailchimp.delay(new_email, 'unsubscribed')

        # New email address and changes above are saved here.
        profile_form.save()
        user_form.save()

        return HttpResponseRedirect(reverse('view_settings'))
    return render(request, 'profile/settings.html', {
        'profile_form': profile_form,
        'user_form': user_form,
        'private': True
    })