librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1172] Patch from Piotr to fix bug#26299 (profile dele


From: Clint Adams
Subject: [Librefm-commits] [1172] Patch from Piotr to fix bug#26299 (profile deletion)
Date: Mon, 04 May 2009 00:22:59 +0000

Revision: 1172
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1172
Author:   clint
Date:     2009-05-04 00:22:58 +0000 (Mon, 04 May 2009)
Log Message:
-----------
Patch from Piotr to fix bug#26299 (profile deletion)

Ticket Links:
:-----------
    http://savannah.gnu.org/bugs/?26299

Modified Paths:
--------------
    trunk/gnukebox/install.php

Added Paths:
-----------
    trunk/nixtape/delete_profile.php
    trunk/nixtape/themes/librefm/templates/delete_profile.tpl
    trunk/nixtape/utils/random_code_generator.php

Modified: trunk/gnukebox/install.php
===================================================================
--- trunk/gnukebox/install.php  2009-05-03 22:18:59 UTC (rev 1171)
+++ trunk/gnukebox/install.php  2009-05-04 00:22:58 UTC (rev 1172)
@@ -226,6 +226,13 @@
                        url VARCHAR(255),
                        expires INTEGER NOT NULL DEFAULT 0,
                        PRIMARY KEY(username,session))");
+       
+       //Table for delete profile requests             
+       $res = $mdb2->query("CREATE TABLE Delete_Request (
+                       code VARCHAR(300), 
+                       expire INT, 
+                       username VARCHAR(100) REFERENCES Users(username),
+                       PRIMARY KEY(code)");
 
        $res = $mdb2->exec("CREATE TABLE Scrobble_Track(
                        id SERIAL PRIMARY KEY,

Added: trunk/nixtape/delete_profile.php
===================================================================
--- trunk/nixtape/delete_profile.php                            (rev 0)
+++ trunk/nixtape/delete_profile.php    2009-05-04 00:22:58 UTC (rev 1172)
@@ -0,0 +1,66 @@
+<?php
+/* Libre.fm -- a free network service for sharing your music listening habits
+ Copyright (C) 2009 Libre.fm Project
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ This program 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 General Public License for more details.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+require_once ('database.php');
+require_once ('templating.php');
+require_once ('data/User.php');
+require_once ('utils/random_code_generator.php');
+if ($logged_in == false) {
+       $smarty->assign('error', 'Error!');
+       $smarty->assign('details', 'Not logged in! You shouldn\'t be here!');
+       $smarty->display('error.tpl');
+       die ();
+} elseif ( isset ($_GET['code'])) {
+       //TODO: Implement expiration
+       $user = new User($_SESSION['user']->name);
+       $username = $user->name;
+       $code = $_GET['code'];
+       $res = $mdb2->query("SELECT * FROM Delete_Request WHERE username = 
".$mdb2->quote($username, 'text').' AND code = '.$mdb2->quote($code, 'text'));
+       if (PEAR::isError($res)) {
+               print_r($res);
+               exit ;
+       }
+       if (!$res->numRows()) {
+               $error = 'Invalid code.';
+               $smarty->assign('error', 'Error!');
+               $smarty->assign('details', $error);
+               $smarty->display('error.tpl');
+               die ();
+       } else {
+               $mdb2->query("DELETE FROM Users WHERE lower(username) = 
".$mdb2->quote(strtolower($username), 'text'));
+               $mdb2->query("DELETE FROM Scrobble_Sessions WHERE username = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Delete_Request WHERE username = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Auth WHERE username = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Group_Members WHERE member = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Radio_Sessions WHERE username = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Recovery_Request WHERE username = 
".$mdb2->quote($username, 'text'));
+               $mdb2->query("DELETE FROM Scrobbles WHERE username = 
".$mdb2->quote($username, 'text'));
+               session_destroy();
+               header("Location: index.php");
+       }
+} else {
+       $user = new User($_SESSION['user']->name);
+       $code = generateCode();
+       $username = $user->name;
+       $email = $user->email;
+       $expire = time()+86400;
+       $mdb2->query("INSERT INTO Delete_Request VALUES (".$mdb2->quote($code, 
'text').', '.$mdb2->quote($expire, 'text').",".$mdb2->quote($username, 
'text').')');
+       $url = $base_url."/delete_profile.php?code=".$code;
+       $content = "Hi!\n\nSomeone from the IP-address 
".$_SERVER['REMOTE_ADDR']." requested "."account delete @ libre.fm. To remove 
acount click: \n\n".$url."\n\n- The Libre.fm Team";
+       $headers = 'From: Libre.fm <address@hidden>';
+       $subject = 'Libre.fm Account Delete Request - Action needed!';
+       mail($email, $subject, $text, $headers);
+       $smarty->display('delete_profile.tpl');
+}
+?>

Added: trunk/nixtape/themes/librefm/templates/delete_profile.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/delete_profile.tpl                   
        (rev 0)
+++ trunk/nixtape/themes/librefm/templates/delete_profile.tpl   2009-05-04 
00:22:58 UTC (rev 1172)
@@ -0,0 +1,6 @@
+{include file='header.tpl'}
+
+<h2 property="dc:title">Remove your profile</h2>
+<p><strong>Confirmation mail has been sent. Thank you</strong></p>
+
+{include file='footer.tpl'}
\ No newline at end of file

Added: trunk/nixtape/utils/random_code_generator.php
===================================================================
--- trunk/nixtape/utils/random_code_generator.php                               
(rev 0)
+++ trunk/nixtape/utils/random_code_generator.php       2009-05-04 00:22:58 UTC 
(rev 1172)
@@ -0,0 +1,31 @@
+<?php
+/* Libre.fm -- a free network service for sharing your music listening habits
+
+   Copyright (C) 2009 Libre.fm Project
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Affero General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU Affero General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+       /**
+        * Used for random code generation
+        * 
+        * @author piotrszulawski
+        * @return (String) code
+        */
+       function generateCode() {
+        $code = md5(uniqid(mt_rand(rand(), rand()), true));
+           return $code;
+       }
+?>
\ No newline at end of file





reply via email to

[Prev in Thread] Current Thread [Next in Thread]