delete-profile.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('templating.php');
  16. require_once('data/User.php');
  17. require_once('utils/random_code_generator.php');
  18. if ($logged_in == false) {
  19. displayError("Error", "Not logged in. You shouldn't be here.");
  20. } else if (isset($_GET['code'])) {
  21. $adodb->Execute('DELETE FROM Delete_Request WHERE expires < ' . (int)(time()));
  22. $username = $this_user->name;
  23. $code = $_GET['code'];
  24. try {
  25. $res = $adodb->GetRow('SELECT * FROM Delete_Request WHERE username = ' . $adodb->qstr($username) . ' AND code = ' . $adodb->qstr($code));
  26. } catch (Exception $e) {
  27. exit;
  28. }
  29. if (!$res) {
  30. displayError("Error", "Invalid code.");
  31. } else {
  32. try {
  33. $adodb->Execute('DELETE FROM Scrobble_Sessions WHERE userid = ' . $this_user->uniqueid);
  34. $adodb->Execute('DELETE FROM Delete_Request WHERE username = ' . $adodb->qstr($username));
  35. $adodb->Execute('DELETE FROM Auth WHERE username = ' . $adodb->qstr($username));
  36. $adodb->Execute('DELETE FROM Group_Members WHERE member = ' . $this_user->uniqueid);
  37. $adodb->Execute('DELETE FROM Radio_Sessions WHERE username = ' . $adodb->qstr($username));
  38. $adodb->Execute('DELETE FROM Recovery_Request WHERE username = ' . $adodb->qstr($username));
  39. $adodb->Execute('DELETE FROM Scrobbles WHERE userid = ' . $this_user->uniqueid);
  40. $adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid1 = ' . $this_user->uniqueid);
  41. $adodb->Execute('DELETE FROM User_Relationship_Flags WHERE uid2 = ' . $this_user->uniqueid);
  42. $adodb->Execute('DELETE FROM User_Relationships WHERE uid1 = ' . $this_user->uniqueid);
  43. $adodb->Execute('DELETE FROM User_Relationships WHERE uid2 = ' . $this_user->uniqueid);
  44. $adodb->Execute('DELETE FROM Banned_Tracks WHERE userid = ' . $this_user->uniqueid);
  45. $adodb->Execute('DELETE FROM Loved_Tracks WHERE userid = ' . $this_user->uniqueid);
  46. $adodb->Execute('DELETE FROM Service_Connections WHERE userid = ' . $this_user->uniqueid);
  47. $adodb->Execute('DELETE FROM Users WHERE uniqueid = ' . $this_user->uniqueid);
  48. } catch (Exception $e) {
  49. displayError("Error", "Something went amiss.");
  50. }
  51. session_destroy();
  52. $smarty->display('account-deleted.tpl');
  53. }
  54. } else {
  55. $code = generateCode();
  56. $username = $this_user->name;
  57. $email = $this_user->email;
  58. $expire = time() + 86400;
  59. $adodb->Execute('INSERT INTO Delete_Request (code, expires, username) VALUES (' . $adodb->qstr($code) . ', ' . $adodb->qstr($expire) . ',' . $adodb->qstr($username) . ')');
  60. $url = $base_url . '/delete-profile.php?code=' . $code;
  61. $content = "Hi!\n\nSomeone from the IP address " . $_SERVER['REMOTE_ADDR'] . " requested account deletion at " . $site_name . ". To remove this account click: \n\n" . $url . "\n\n- The " . $site_name . " Team";
  62. $subject = $site_name . ' Account Delete Request - Action needed!';
  63. mail($email, $subject, $content);
  64. $smarty->display('delete-profile.tpl');
  65. }