librefm-commits
[Top][All Lists]
Advanced

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

[Librefm-commits] [1744] switch Scrobble_Sessions from username to useri


From: Clint Adams
Subject: [Librefm-commits] [1744] switch Scrobble_Sessions from username to userid
Date: Sat, 23 May 2009 20:58:26 +0000

Revision: 1744
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1744
Author:   clint
Date:     2009-05-23 20:58:26 +0000 (Sat, 23 May 2009)
Log Message:
-----------
switch Scrobble_Sessions from username to userid

Modified Paths:
--------------
    trunk/gnukebox/install.php
    trunk/gnukebox/scrobble-utils.php
    trunk/gnukebox/submissions/1.1/handshake.php
    trunk/gnukebox/submissions/1.2/handshake.php
    trunk/nixtape/auth.php
    trunk/nixtape/data/User.php
    trunk/nixtape/delete-profile.php
    trunk/nixtape/login.php

Modified: trunk/gnukebox/install.php
===================================================================
--- trunk/gnukebox/install.php  2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/gnukebox/install.php  2009-05-23 20:58:26 UTC (rev 1744)
@@ -183,7 +183,7 @@
                stid INTEGER)");
 
        $adodb->Execute("CREATE TABLE Scrobble_Sessions(
-               username VARCHAR(64) REFERENCES Users(username),
+               userid INTEGER REFERENCES Users(uniqueid),
                sessionid VARCHAR(32) PRIMARY KEY,
                client CHAR(3),
                expires INTEGER)");

Modified: trunk/gnukebox/scrobble-utils.php
===================================================================
--- trunk/gnukebox/scrobble-utils.php   2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/gnukebox/scrobble-utils.php   2009-05-23 20:58:26 UTC (rev 1744)
@@ -32,7 +32,7 @@
        $adodb->Execute('DELETE FROM Scrobble_Sessions WHERE expires < ' . 
time());
 
        try {
-               $res = $adodb->GetOne('SELECT username FROM Scrobble_Sessions 
WHERE sessionid = ' . $adodb->qstr($session_id)); // get the username from the 
table
+               $res = $adodb->GetOne('SELECT user FROM Scrobble_Sessions WHERE 
sessionid = ' . $adodb->qstr($session_id)); // get the username from the table
        }
        catch (exception $e) {
                die('FAILED ufs ' . $e->getMessage() . '\n');
@@ -45,7 +45,8 @@
                // the user has no session
        }
 
-       return $res;
+       $username = uniqueid_to_username($res);
+       return $username;
 
               // return the first user
 }
@@ -229,16 +230,43 @@
 }
 
 function validateMBID ($input) {
-if(isset($input)) {
-       $input = strtolower(rtrim($input));
-       
if(preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
 $input)) {
-               return $input;
+       if(isset($input)) {
+               $input = strtolower(rtrim($input));
+               
if(preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
 $input)) {
+                       return $input;
+               } else {
+                       return null;
+               }
        } else {
                return null;
        }
-} else {
-       return null;
+
 }
 
+function username_to_uniqueid($username) {
+       global $adodb;
+
+       $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
+       try {
+               $uniqueid = GetOne('SELECT uniqueid from Users where 
lower(username) = lower('.$adodb->qstr($username).')');
+       } catch (exception $e) {
+               return null;
+       }
+
+       return $uniqueid;
 }
+
+function uniqueid_to_username($uniqueid) {
+       global $adodb;
+
+       $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
+       try {
+               $username = GetOne('SELECT username from Users where uniqueid) 
= '.($uniqueid));
+       } catch (exception $e) {
+               return null;
+       }
+
+       return $username;
+}
+
 ?>

Modified: trunk/gnukebox/submissions/1.1/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.1/handshake.php        2009-05-23 20:25:51 UTC 
(rev 1743)
+++ trunk/gnukebox/submissions/1.1/handshake.php        2009-05-23 20:58:26 UTC 
(rev 1744)
@@ -42,20 +42,22 @@
 
 $timestamp = time();
 
+$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
 try {
-       $res = $adodb->GetOne("SELECT password FROM Users WHERE username = ". 
$adodb->qstr($username));
+       $row = $adodb->GetRow('SELECT uniqueid,password FROM Users WHERE 
username = '. $adodb->qstr($username));
 }
 catch (exception $e) {
        die("FAILED " . $e->getMessage() . "\n");
 }
-if(!$res) {
+if(!$row) {
        die("BADUSER\n");
 }
-$password = $res;
+$password = $row['password'];
+$uniqueid = $row['uniqueid'];
 $session_id = md5($password . $timestamp);
 try {
-$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(username, sessionid, 
client, expires) VALUES ("
-       . $adodb->qstr($username, "text") . ","
+$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(userid, sessionid, 
client, expires) VALUES ("
+       . ($uniqueid) . ","
        . $adodb->qstr($session_id, "text") . ","
        . $adodb->qstr($client, "text") . ","
        . $adodb->qstr(time() + 86400) . ")");

Modified: trunk/gnukebox/submissions/1.2/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.2/handshake.php        2009-05-23 20:25:51 UTC 
(rev 1743)
+++ trunk/gnukebox/submissions/1.2/handshake.php        2009-05-23 20:58:26 UTC 
(rev 1744)
@@ -54,9 +54,10 @@
        die("BADAUTH\n");
 }
 
+$uniqueid = username_to_uniqueid($username);
 $session_id = md5($auth_token . time());
-$sql = "INSERT INTO Scrobble_Sessions(username, sessionid, client, expires) 
VALUES ("
-       . $adodb->qstr($username) . ","
+$sql = "INSERT INTO Scrobble_Sessions(userid, sessionid, client, expires) 
VALUES ("
+       . ($uniqueid) . ","
        . $adodb->qstr($session_id) . ","
        . $adodb->qstr($client) . ","
        . (time() + 86400) . ")";

Modified: trunk/nixtape/auth.php
===================================================================
--- trunk/nixtape/auth.php      2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/nixtape/auth.php      2009-05-23 20:58:26 UTC (rev 1744)
@@ -26,7 +26,7 @@
        $err = 0;
        $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
        try {
-               $row = $adodb->GetRow('SELECT username FROM Scrobble_Sessions 
WHERE '
+               $row = $adodb->GetRow('SELECT user FROM Scrobble_Sessions WHERE 
'
                                . 'sessionid = ' . 
$adodb->qstr($_COOKIE['session_id'])
                                . ' AND expires > ' . (int)(time()));
        }
@@ -40,7 +40,8 @@
                session_destroy();
        } else {
                $logged_in = true;
-               $this_user = new User($row['username']);
+               $username = uniqueid_to_username();
+               $this_user = new User($username);
        }
 }
 ?>

Modified: trunk/nixtape/data/User.php
===================================================================
--- trunk/nixtape/data/User.php 2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/nixtape/data/User.php 2009-05-23 20:58:26 UTC (rev 1744)
@@ -203,8 +203,8 @@
        function getScrobbleSession() {
                global $adodb;
                $session_id = md5(mt_rand() . time());
-               $sql = 'INSERT INTO Scrobble_Sessions(username, sessionid, 
client, expires) VALUES ('
-                       . $adodb->qstr($this->name) . ','
+               $sql = 'INSERT INTO Scrobble_Sessions(userid, sessionid, 
client, expires) VALUES ('
+                       . ($this->uniqueid) . ','
                        . $adodb->qstr($session_id) . ','
                        . '\'lfm\','
                        . (time() + 86400) . ')';

Modified: trunk/nixtape/delete-profile.php
===================================================================
--- trunk/nixtape/delete-profile.php    2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/nixtape/delete-profile.php    2009-05-23 20:58:26 UTC (rev 1744)
@@ -46,7 +46,7 @@
                $smarty->display('error.tpl');
                die ();
        } else {
-               $adodb->Execute('DELETE FROM Scrobble_Sessions WHERE username = 
' . $adodb->qstr($username));
+               $adodb->Execute('DELETE FROM Scrobble_Sessions WHERE userid = ' 
. $adodb->qstr($this_user->uniqueid));
                $adodb->Execute('DELETE FROM Delete_Request WHERE username = ' 
. $adodb->qstr($username));
                $adodb->Execute('DELETE FROM Auth WHERE username = ' . 
$adodb->qstr($username));
                $adodb->Execute('DELETE FROM Group_Members WHERE member = ' . 
(int)($this_user->uniqueid));

Modified: trunk/nixtape/login.php
===================================================================
--- trunk/nixtape/login.php     2009-05-23 20:25:51 UTC (rev 1743)
+++ trunk/nixtape/login.php     2009-05-23 20:58:26 UTC (rev 1744)
@@ -42,14 +42,14 @@
 
        if(empty($errors)) {
                try {
-               $res = $adodb->GetOne('SELECT username FROM Users WHERE '
+               $userid = $adodb->GetOne('SELECT uniqueid FROM Users WHERE '
                        . ' lower(username) = ' . 
$adodb->qstr(strtolower($username))
                        . ' AND password = ' . $adodb->qstr(md5($password)) . ' 
AND active = 1');
                }
                catch (exception $e) {
                        $errors .= 'A database error happened.';
                }
-               if(!$res) {
+               if(!$userid) {
                        $errors .= 'Invalid username or password.';
                        $smarty->assign('invalid', true);
                } else {
@@ -60,8 +60,8 @@
                        } else {
                                $session_time = time() + 86400; // 1 day
                        }
-                       $adodb->Execute('INSERT INTO Scrobble_Sessions 
(username, sessionid, expires) VALUES ('
-                               . $adodb->qstr($username) . ', '
+                       $adodb->Execute('INSERT INTO Scrobble_Sessions (userid, 
sessionid, expires) VALUES ('
+                               . ($userid) . ', '
                                . $adodb->qstr($session_id) . ', '
                                . (int)($session_time) . ')');
 





reply via email to

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