-
Notifications
You must be signed in to change notification settings - Fork 4
/
_deleteAccount.php
142 lines (111 loc) · 4.44 KB
/
_deleteAccount.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/*
Copyright 2020 FWBer.com
This file is part of FWBer.
FWBer is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FWBer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero Public License for more details.
You should have received a copy of the GNU Affero Public License
along with FWBer. If not, see <https://www.gnu.org/licenses/>.
*/
session_start();
include("_debug.php");
include("_names.php");
include("_init.php");
include("_secrets.php");
if($_SERVER["REQUEST_METHOD"] != "POST"){header('Location: '.getSiteURL());exit();}
require_once("_profileVars.php");
require_once("_globals.php");
//first make sure we are a legit user.
if(validateSessionOrCookiesReturnLoggedIn()==false){header('Location: '.getSiteURL());exit();}//full auth for actions
goHomeIfCookieNotSet();
$db = mysqli_connect($dburl,$dbuser,$dbpass);
if(!$db)exit(mysqli_connect_error());
//make sure we've got an action.
if(!isset($_POST['myPass'])||empty($_POST['myPass']))exit('myPass'); else $myPass= mysqli_escape_string($db,$_POST['myPass']);
if(!isset($_POST['myPassAgain'])||empty($_POST['myPassAgain']))exit('myPassAgain'); else $myPassAgain= mysqli_escape_string($db,$_POST['myPassAgain']);
if(!isset($_POST['goodbyeCheck'])||empty($_POST['goodbyeCheck']))exit('goodbyeCheck'); else $goodbyeCheck= mysqli_escape_string($db,$_POST['goodbyeCheck']);
if($myPass!=$myPassAgain)exit("Passwords don't match");
if($goodbyeCheck!="goodbye")exit("Didn't say goodbye.");
//authenticate old pass
$email = mysqli_real_escape_string($db,$_SESSION["email"]);
$dbquerystring = sprintf("SELECT passwordHash, dateJoined, publicPics, privatePics FROM ".$dbname.".users WHERE email='%s'",$email);
$dbquery = mysqli_query($db, $dbquerystring);
$dbresults = mysqli_fetch_array($dbquery);
mysqli_free_result($dbquery);
$message = "";
if(
$dbresults==null
||$dbresults['passwordHash']==null
||getSaltedPassword($myPass,$dbresults['dateJoined'])!=$dbresults['passwordHash']
)
{
$message = "Password was wrong.";
}
if($message=="")
{
//connect to database, find any pictures for me.
//delete them in the db too.
$publicPics=explode(",",trim(trim($dbresults['publicPics']),","));
$privatePics=explode(",",trim(trim($dbresults['privatePics']),","));
//delete pics
foreach($publicPics as &$s)
{
if($s=="")continue;
unlink("./fwberImageStore/".$s);
unlink("./fwberImageStore/".$s."_b");
$s = "";
}
foreach($privatePics as &$s)
{
if($s=="")continue;
unlink("./fwberImageStore/".$s);
unlink("./fwberImageStore/".$s."_b");
$s = "";
}
//delete pics in database
$dbquerystring =
sprintf("UPDATE ".$dbname.".users SET publicPics = '%s',privatePics = '%s' WHERE email='%s'",
trim(trim(implode(",",$publicPics)),","),
trim(trim(implode(",",$privatePics)),","),
$email
);
if(!mysqli_query($db,$dbquerystring))exit("didn't work");
//remove user from database
$dbquerystring =
sprintf("DELETE FROM ".$dbname.".users WHERE email='%s'",
$email
);
if(!mysqli_query($db,$dbquerystring))exit("didn't work");
//delete cookies
setcookie("email","",time()-1000,'/',".".getSiteDomain());
setcookie("token","",time()-1000,'/',".".getSiteDomain());
session_destroy();
mysqli_close($db);
$message = "Your account has been deleted.";
}
?>
<!doctype html>
<html lang="en">
<head>
<title><?php require_once("_names.php"); echo getSiteName(); ?> - Delete Account<?php require_once("_names.php"); echo getTitleTagline(); ?></title>
<?php include("head.php");?>
</head>
<body class="d-flex flex-column h-100">
<?php include("h.php");?>
<div id="mainbody" align="center">
<br>
<br>
<br>
<div style="font-size:14px;">
<?php echo $message; ?>
</div>
</div>
<?php include("f.php");?>
</body>
</html>