diff options
Diffstat (limited to 'pyload/database')
-rw-r--r-- | pyload/database/FileDatabase.py | 12 | ||||
-rw-r--r-- | pyload/database/UserDatabase.py | 21 |
2 files changed, 14 insertions, 19 deletions
diff --git a/pyload/database/FileDatabase.py b/pyload/database/FileDatabase.py index e6e051a92..3bd12ca80 100644 --- a/pyload/database/FileDatabase.py +++ b/pyload/database/FileDatabase.py @@ -38,8 +38,8 @@ class FileMethods(DatabaseMethods): self.c.execute("SELECT COUNT(*), SUM(f.size) FROM files f WHERE dlstatus != 0") else: self.c.execute( - "SELECT COUNT(*), SUM(f.size) FROM files f, packages p WHERE f.package = p.pid AND dlstatus != 0", - user) + "SELECT COUNT(*), SUM(f.size) FROM files f WHERE f.owner=? AND dlstatus != 0", + (user,)) r = self.c.fetchone() # sum is None when no elements are added @@ -54,8 +54,8 @@ class FileMethods(DatabaseMethods): self.c.execute("SELECT COUNT(*), SUM(f.size) FROM files f WHERE dlstatus NOT IN (0,5,6)") else: self.c.execute( - "SELECT COUNT(*), SUM(f.size) FROM files f, package p WHERE f.package = p.pid AND p.owner=? AND dlstatus NOT IN (0,5,6)", - user) + "SELECT COUNT(*), SUM(f.size) FROM files f WHERE f.owner=? AND dlstatus NOT IN (0,5,6)", + (user,)) r = self.c.fetchone() return (r[0], r[1] if r[1] is not None else 0) if r else (0, 0) @@ -75,8 +75,8 @@ class FileMethods(DatabaseMethods): self.c.execute("SELECT COUNT(*), SUM(size) FROM files WHERE dlstatus IN (2,3,8,9,10)") else: self.c.execute( - "SELECT COUNT(*), SUM(f.size) FROM files f, packages p WHERE f.package = p.pid AND dlstatus IN (2,3,8,9,10)", - user) + "SELECT COUNT(*), SUM(f.size) FROM files f WHERE f.owner=? AND dlstatus IN (2,3,8,9,10)", + (user,)) r = self.c.fetchone() return (r[0], r[1] if r[1] is not None else 0) if r else (0, 0) diff --git a/pyload/database/UserDatabase.py b/pyload/database/UserDatabase.py index 14b4ae40c..65f46169e 100644 --- a/pyload/database/UserDatabase.py +++ b/pyload/database/UserDatabase.py @@ -32,22 +32,25 @@ def random_salt(): class UserMethods(DatabaseMethods): @queue - def addUser(self, user, password): + def addUser(self, user, password, role, permission): salt = random_salt() h = sha1(salt + password) password = salt + h.hexdigest() self.c.execute('SELECT name FROM users WHERE name=?', (user, )) if self.c.fetchone() is not None: - self.c.execute('UPDATE users SET password=? WHERE name=?', (password, user)) + self.c.execute('UPDATE users SET password=?, role=?, permission=? WHERE name=?', + (password, role, permission, user)) else: - self.c.execute('INSERT INTO users (name, password) VALUES (?, ?)', (user, password)) + self.c.execute('INSERT INTO users (name, role, permission, password) VALUES (?, ?, ?, ?)', + (user, role, permission, password)) @queue def addDebugUser(self, uid): # just add a user with uid to db try: - self.c.execute('INSERT INTO users (uid, name, password) VALUES (?, ?, ?)', (uid, "debugUser", random_salt())) + self.c.execute('INSERT INTO users (uid, name, password) VALUES (?, ?, ?)', + (uid, "debugUser", random_salt())) except: pass @@ -116,18 +119,10 @@ class UserMethods(DatabaseMethods): return False - @async - def setPermission(self, user, perms): - self.c.execute("UPDATE users SET permission=? WHERE name=?", (perms, user)) - - @async - def setRole(self, user, role): - self.c.execute("UPDATE users SET role=? WHERE name=?", (role, user)) - # TODO update methods @async def removeUserByName(self, name): - self.c.execute("SELECT uid from users WHERE name=?", (name,)) + self.c.execute("SELECT uid FROM users WHERE name=?", (name,)) uid = self.c.fetchone() if uid: # deletes user and all associated accounts |