summaryrefslogtreecommitdiffstats
path: root/module/database/UserDatabase.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-06-03 17:45:10 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2012-06-03 17:45:10 +0200
commit0d2d6daef850ac6bcc7fafccd230e52d2a862c2c (patch)
tree73e36baba63e4c0895149bab9fe698d32f405828 /module/database/UserDatabase.py
parentsmall typo fixes and TODOs (diff)
downloadpyload-0d2d6daef850ac6bcc7fafccd230e52d2a862c2c.tar.xz
updates for database + api
Diffstat (limited to 'module/database/UserDatabase.py')
-rw-r--r--module/database/UserDatabase.py117
1 files changed, 66 insertions, 51 deletions
diff --git a/module/database/UserDatabase.py b/module/database/UserDatabase.py
index 6bfb02bbd..bed4e94a9 100644
--- a/module/database/UserDatabase.py
+++ b/module/database/UserDatabase.py
@@ -1,42 +1,28 @@
# -*- coding: utf-8 -*-
-"""
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU 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 General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- @author: mkaay
-"""
+###############################################################################
+# Copyright(c) 2008-2012 pyLoad Team
+# http://www.pyload.org
+#
+# This file is part of pyLoad.
+# pyLoad 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.
+#
+# Subjected to the terms and conditions in LICENSE
+#
+# @author: RaNaN
+###############################################################################
from hashlib import sha1
import random
+from module.Api import UserData
+
from DatabaseBackend import DatabaseMethods, queue, async
class UserMethods(DatabaseMethods):
- @queue
- def checkAuth(self, user, password):
- self.c.execute('SELECT rowid, name, password, role, permission, template, email FROM "users" WHERE name=?', (user, ))
- r = self.c.fetchone()
- if not r:
- return {}
-
- salt = r[2][:5]
- pw = r[2][5:]
- h = sha1(salt + password)
- if h.hexdigest() == pw:
- return {"id": r[0], "name": r[1], "role": r[3],
- "permission": r[4], "template": r[5], "email": r[6]}
- else:
- return {}
@queue
def addUser(self, user, password):
@@ -50,8 +36,53 @@ class UserMethods(DatabaseMethods):
else:
self.c.execute('INSERT INTO users (name, password) VALUES (?, ?)', (user, password))
+ @queue
+ def getUserData(self, name=None, uid=None):
+ qry = ('SELECT uid, name, email, role, permission, folder, traffic, dllimit, dlquota, '
+ 'hddquota, user, template FROM "users" WHERE ')
+
+ if name is not None:
+ self.c.execute(qry + "name=?", (name,))
+ r = self.c.fetchone()
+ if r:
+ return UserData(*r)
+
+ elif uid is not None:
+ self.c.execute(qry + "uid=?", (uid,))
+ r = self.c.fetchone()
+ if r:
+ return UserData(*r)
+
+ return None
@queue
+ def getAllUserData(self):
+ self.c.execute('SELECT uid, name, email, role, permission, folder, traffic, dllimit, dlquota, '
+ 'hddquota, user, template FROM "users"')
+ user = {}
+ for r in self.c:
+ user[r[0]] = UserData(*r)
+
+ return user
+
+
+ @queue
+ def checkAuth(self, user, password):
+ self.c.execute('SELECT uid, name, email, role, permission, folder, traffic, dllimit, dlquota, '
+ 'hddquota, user, template password FROM "users" WHERE name=?', (user, ))
+ r = self.c.fetchone()
+ if not r:
+ return None
+
+ salt = r[-1][:5]
+ pw = r[-1][5:]
+ h = sha1(salt + password)
+ if h.hexdigest() == pw:
+ return UserData(*r[:-1])
+ else:
+ return None
+
+ @queue #TODO
def changePassword(self, user, oldpw, newpw):
self.c.execute('SELECT rowid, name, password FROM users WHERE name=?', (user, ))
r = self.c.fetchone()
@@ -71,7 +102,6 @@ class UserMethods(DatabaseMethods):
return False
-
@async
def setPermission(self, user, perms):
self.c.execute("UPDATE users SET permission=? WHERE name=?", (perms, user))
@@ -80,26 +110,11 @@ class UserMethods(DatabaseMethods):
def setRole(self, user, role):
self.c.execute("UPDATE users SET role=? WHERE name=?", (role, user))
+ # TODO update methods
- @queue
- def listUsers(self):
- self.c.execute('SELECT name FROM users')
- users = []
- for row in self.c:
- users.append(row[0])
- return users
-
- @queue
- def getAllUserData(self):
- self.c.execute("SELECT name, permission, role, template, email FROM users")
- user = {}
- for r in self.c:
- user[r[0]] = {"permission": r[1], "role": r[2], "template": r[3], "email": r[4]}
-
- return user
-
- @queue
- def removeUser(self, user):
- self.c.execute('DELETE FROM users WHERE name=?', (user, ))
+ @async
+ def removeUser(self, uid=None):
+ # deletes user and all associated accounts
+ self.c.execute('DELETE FROM users WHERE user=?', (uid, ))
UserMethods.register()