Exemplo n.º 1
0
    def bulk_delete(cls, ids):
        """
        Override the general bulk_delete method because we need to delete them
        one at a time while also deleting them on Stripe.

        :param ids: List of ids to be deleted
        :type ids: list
        :return: int
        """
        delete_count = 0

        for id in ids:
            user = User.query.get(id)

            if user is None:
                continue

            if user.subscription is None:
                user.delete()
            else:
                subscription = Subscription()
                cancelled = subscription.cancel(user=user)

                # If successful, delete it locally.
                if cancelled:

                    user.delete()

            delete_count += 1

        return delete_count
Exemplo n.º 2
0
def cancel():

    form = CancelSubscriptionForm()

    if form.validate_on_submit():

        # Cancel the user's subscription
        if current_user.subscription:
            subscription = Subscription()
            canceled = subscription.cancel(user=current_user)
        else:
            # If there is no subscription, then delete the user
            canceled = True

        if canceled:

            # Get the user's email
            email = current_user.email

            # Clear the cache.
            mailbox_id = current_user.mailbox_id
            if cache.get(mailbox_id):
                cache.delete(mailbox_id)

            from app.blueprints.parse.models.mailbox import Mailbox

            # Delete the credentials from MG
            for mailbox in Mailbox.query.filter_by(user_email=email).all():
                delete_inbox(mailbox.mailbox_id)

            # Delete all emails, rules and mailboxes belonging to the user.
            from app.blueprints.user.tasks import delete_all
            delete_all.delay(email, mailbox_id)

            # Delete the user.
            from app.blueprints.billing.tasks import delete_users
            ids = [current_user.id]
            delete_users(ids)

            # Send a cancellation email.
            from app.blueprints.user.tasks import send_cancel_email
            send_cancel_email.delay(email)

            flash('Sorry to see you go! Your subscription has been canceled.',
                  'success')
            return redirect(url_for('user.login'))

    return render_template('billing/cancel.html', form=form)
Exemplo n.º 3
0
def users_cancel_subscription():
    form = UserCancelSubscriptionForm()

    if form.validate_on_submit():
        user = User.query.get(request.form.get('id'))

        if user:
            subscription = Subscription()
            if subscription.cancel(user):
                flash('Subscription has been canceled for {0}.'
                      .format(user.name), 'success')
        else:
            flash('No subscription was canceled, something went wrong.',
                  'danger')

    return redirect(url_for('admin.users'))
Exemplo n.º 4
0
def cancel():
    from app.blueprints.base.functions import print_traceback
    try:
        form = CancelSubscriptionForm()

        if form.validate_on_submit():

            # If there is no subscription, then delete the user
            canceled = True

            # Cancel the user's subscription
            if current_user.subscription:
                subscription = Subscription()
                canceled = subscription.cancel(user=current_user)

            if canceled:
                # Set the user to inactive
                from app.blueprints.base.functions import set_inactive
                set_inactive(current_user)

                logout_user()

                # Get the user's email
                # email = current_user.email

                # Delete the user.
                # from app.blueprints.billing.tasks import delete_users
                # ids = [current_user.id]

                # Delete the user
                # delete_users.delay(ids)
                # current_user.delete()

                # Send a cancellation email.
                from app.blueprints.user.tasks import send_cancel_email
                # send_cancel_email.delay(email)

                flash(
                    'Sorry to see you go! Your subscription has been canceled.',
                    'success')
                return redirect(url_for('user.signup'))

        return render_template('billing/cancel.html', form=form)
    except Exception as e:
        print_traceback(e)
        return redirect(url_for('user.settings'))
Exemplo n.º 5
0
def cancel():

    form = CancelSubscriptionForm()

    if form.validate_on_submit():

        # Cancel the user's subscription
        if current_user.subscription:
            subscription = Subscription()
            canceled = subscription.cancel(user=current_user)
        else:
            # If there is no subscription, then delete the user
            canceled = True

        if canceled:

            # Get the user's email
            email = current_user.email

            # Delete the user.
            from app.blueprints.billing.tasks import delete_users, delete_auth
            from app.blueprints.api.models.app_auths import AppAuthorization
            ids = [current_user.id]

            # Delete the app auths
            for id in ids:
                auths = [
                    x.id for x in AppAuthorization.query.filter(
                        AppAuthorization.user_id == id).all()
                ]
                delete_auth.delay(auths)

            # Delete the user
            delete_users.delay(ids)

            # Send a cancellation email.
            from app.blueprints.user.tasks import send_cancel_email
            send_cancel_email.delay(email)

            flash('Sorry to see you go! Your subscription has been canceled.',
                  'success')
            return redirect(url_for('user.login'))

    return render_template('billing/cancel.html', form=form)