close_account.pl
108 lines of code
1
#!/usr/local/bin/perl
2
3
# must have's!
4
use strict;
5
use warnings;
6
use CGI::Carp qw(fatalsToBrowser);
7
use DBI;
8
use URI::Escape;
9
10
use lib "/var/www/html/Pm";
11
12
use Html qw(pre_html_header);
13
use Bc_chef qw(cookie_get cookie_delete);
14
use Bc_misc qw(get_param referrer);
15
use Bc_sql qw(get_constant
16
              sql_execute
17
              user_exists
18
              $QUERY_PAGE
19
              $QUERY_UID
20
              $LOGGEDIN
21
22
              $DB
23
             );
24
25
use Redir qw(error_redir notice_redir);
26
use Security qw(banned);
27
28
29
my $DEBUG = 0;
30
my $output;
31
if ($DEBUG) { $output = pre_html_header(); }
32
33
if (not user_exists($LOGGEDIN) or banned($LOGGEDIN)) {
34
  my $msg =  "Access Denied";
35
  if ($DEBUG) { $msg .= " (close_account.pl)"; }
36
  $output = error_redir("/", $msg);
37
} else {
38
  # not only delete user account, but also delete:
39
  #    theme purchases
40
  #    inbox
41
  #    from friends lists (both theirs, and others)
42
  #    images
43
  #    gifts
44
  #    points (aka coins)
45
  #    profile_views
46
  #    beta
47
  #    blocked list
48
49
50
  # we already have a connection to the database, and the currently loggedin user's ID
51
  # okay, so let's start deleting!
52
53
  if (not $DEBUG) {
54
    my $redir = get_param("r");
55
    my $tpsql = "delete from theme_purchases where UID=" . $DB->quote($LOGGEDIN);
56
    my $inboxsql = "delete from messages where to_ID=" . $DB->quote($LOGGEDIN);
57
    my $friendssql = "delete from friends where UID=" . $DB->quote($LOGGEDIN);
58
    my $fromFriendssql = "delete from friends where FID=" . $DB->quote($LOGGEDIN);
59
    my $imgsql = "delete from images where UID=" . $DB->quote($LOGGEDIN);
60
    my $giftsql = "delete from purchased_gifts where UID=" . $DB->quote($LOGGEDIN);
61
    my $pointssql = "delete from coins where ID=" . $DB->quote($LOGGEDIN);
62
    my $viewssql = "delete from profile_views where UID=" . $DB->quote($LOGGEDIN);
63
    my $loggedinsql = "delete from loggedin where UID=" . $DB->quote($LOGGEDIN);
64
    my $usersql = "delete from users where ID=" . $DB->quote($LOGGEDIN);
65
    my $betasql = "delete from beta_users where UID=" . $DB->quote($LOGGEDIN);
66
    my $blockssql = "delete from blocks where UID=" . $DB->quote($LOGGEDIN);
67
68
    my $result = sql_execute($tpsql, "close account, tpsql");
69
    if (not $result) { $output .= "0,"; }
70
    $result = sql_execute($inboxsql, "close account inboxsql");
71
    if (not $result) { $output .= "-1,"; }
72
    $result = sql_execute($friendssql, "close account friendssql");
73
    if (not $result) { $output .= "-2,"; }
74
    $result = sql_execute($fromFriendssql, "close account fromfriendssql");
75
    if (not $result) { $output .= "-3,"; }
76
    $result = sql_execute($imgsql, "close account imgsql");
77
    if (not $result) { $output .= "-4,"; }
78
    $result = sql_execute($pointssql, "close account pointssql");
79
    if (not $result) { $output .= "-5,"; }
80
    $result = sql_execute($viewssql, "close account viewssql");
81
    if (not $result) { $output .= "-6,"; }
82
    $result = sql_execute($loggedinsql, "close account loggedinsql");
83
    if (not $result) { $output .= "-7,"; }
84
    $result = sql_execute($usersql, "close account usersql");
85
    if (not $result) { $output .= "-8,"; }
86
    $result = sql_execute($betasql, "close account betasql");
87
    if (not $result) { $output .= "-9,"; }
88
    $result = sql_execute($blockssql, "close account blockssql");
89
    if (not $result) { $output .= "-10,"; }
90
    $output =~ s/,$/\n/;
91
92
    if ($redir) {
93
      if ($result ne 1) {
94
        $output = error_redir(referrer(), "Could not delete account!");
95
      } else {
96
        $output = cookie_delete("sesh_id");
97
        $output .= notice_redir("/", "Account deleted :(");
98
      }
99
    }
100
  } else {
101
    $output .= "debugging mode enabled...no changes were actually made<br>\n";
102
    $output .= "this process has not yet been completed<br>\n";
103
  }
104
}
105
106
print $output;
107
108
exit 1;