Example #1
0
def settings_remove_discord(v):

    if v.admin_level>1:
        return render_template("settings_filters.html", v=v, error="Admins can't disconnect Discord.")

    remove_user(v)

    v.discord_id=None
    g.db.add(v)
    g.db.commit()

    return redirect("/settings/profile")
Example #2
0
def delete_account(v):

    if not v.verifyPass(request.form.get("password", "")) or (
            v.mfa_secret
            and not v.validate_2fa(request.form.get("twofactor", ""))):
        return render_template("settings_security.html",
                               v=v,
                               error="Invalid password or token"
                               if v.mfa_secret else "Invalid password")

    remove_user(v)

    v.discord_id = None
    v.is_deleted = True
    v.login_nonce += 1
    v.delete_reason = request.form.get("delete_reason", "")
    v.patreon_id = None
    v.patreon_pledge_cents = 0
    v.del_banner()
    v.del_profile()
    g.db.add(v)

    mods = g.db.query(ModRelationship).filter_by(user_id=v.id).all()
    for mod in mods:
        g.db.delete(mod)

    bans = g.db.query(BanRelationship).filter_by(user_id=v.id).all()
    for ban in bans:
        g.db.delete(ban)

    contribs = g.db.query(ContributorRelationship).filter_by(
        user_id=v.id).all()
    for contrib in contribs:
        g.db.delete(contrib)

    blocks = g.db.query(UserBlock).filter_by(target_id=v.id).all()
    for block in blocks:
        g.db.delete(block)

    for b in v.boards_modded:
        if b.mods_count == 0:
            b.is_private = False
            b.restricted_posting = False
            b.all_opt_out = False
            g.db.add(b)

    session.pop("user_id", None)
    session.pop("session_id", None)

    g.db.commit()

    return redirect('/')
Example #3
0
def delete_account(v):

    if not v.verifyPass(request.form.get("password", "")) or (
            v.mfa_secret
            and not v.validate_2fa(request.form.get("twofactor", ""))):
        return render_template("settings_security.html",
                               v=v,
                               error="Invalid password or token"
                               if v.mfa_secret else "Invalid password")

    remove_user(v)

    v.discord_id = None
    v.is_deleted = True
    v.login_nonce += 1
    v.delete_reason = request.form.get("delete_reason", "")
    v.patreon_id = None
    v.patreon_pledge_cents = 0
    v.del_banner()
    v.del_profile()
    g.db.add(v)

    mods = g.db.query(ModRelationship).filter_by(user_id=v.id).all()
    for mod in mods:
        g.db.delete(mod)

    bans = g.db.query(BanRelationship).filter_by(user_id=v.id).all()
    for ban in bans:
        g.db.delete(ban)

    contribs = g.db.query(ContributorRelationship).filter_by(
        user_id=v.id).all()
    for contrib in contribs:
        g.db.delete(contrib)

    blocks = g.db.query(UserBlock).filter_by(target_id=v.id).all()
    for block in blocks:
        g.db.delete(block)

    for b in v.boards_modded:
        if b.mods_count == 0:
            b.is_private = False
            b.restricted_posting = False
            b.all_opt_out = False
            g.db.add(b)

    session.pop("user_id", None)
    session.pop("session_id", None)

    #deal with throwaway spam - auto nuke content if account age below threshold
    if int(time.time()) - v.created_utc < 60 * 60 * 12:
        for post in v.submissions:
            post.is_banned = True

            new_ma = ModAction(user_id=1,
                               kind="ban_post",
                               target_submission_id=post.id,
                               note="spam")

            g.db.add(post)
            g.db.add(new_ma)

        for comment in v.comments:
            comment.is_banned = True
            new_ma = ModAction(user_id=1,
                               kind="ban_comment",
                               target_comment_id=comment.id,
                               note="spam")
            g.db.add(comment)
            g.db.add(new_ma)

    g.db.commit()

    return redirect('/')