diff options
author | mkaay <mkaay@mkaay.de> | 2011-02-05 14:45:36 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2011-02-05 14:45:36 +0100 |
commit | 4c2bc3442e7e953444c28745cbec6ff7b3139b0b (patch) | |
tree | eafa93db353cf4a80c51c9b81211e529ac805759 | |
parent | created unified authentication system (same data for webinterface an GUI/CLI,... (diff) | |
download | pyload-4c2bc3442e7e953444c28745cbec6ff7b3139b0b.tar.xz |
user editor
-rw-r--r-- | module/UserDatabase.py | 17 | ||||
-rw-r--r-- | module/setup.py | 38 | ||||
-rwxr-xr-x | pyLoadCore.py | 2 |
3 files changed, 50 insertions, 7 deletions
diff --git a/module/UserDatabase.py b/module/UserDatabase.py index 54852fae1..471363cf9 100644 --- a/module/UserDatabase.py +++ b/module/UserDatabase.py @@ -49,5 +49,22 @@ class UserMethods(): c.execute('UPDATE users SET password=? WHERE name=?', (password, user)) else: c.execute('INSERT INTO users (name, password) VALUES (?, ?)', (user, password)) + + @style.queue + def listUsers(db): + c = db.createCursor() + c.execute('SELECT name FROM users') + users = [] + for row in c.fetchall(): + users.append(row[0]) + return users + + @style.queue + def removeUser(db, user): + c = db.createCursor() + c.execute('SELECT name FROM users WHERE name=?', (user, )) + if c.fetchone() is not None: + c.execute('DELETE FROM users WHERE name=?', (user, )) + DatabaseBackend.registerSub(UserMethods) diff --git a/module/setup.py b/module/setup.py index e837e08ae..d8776f607 100644 --- a/module/setup.py +++ b/module/setup.py @@ -293,17 +293,43 @@ class Setup(): translation = gettext.translation("setup", join(self.path, "locale"), languages=[self.config["general"]["language"]]) translation.install(unicode=(True if sys.getfilesystemencoding().startswith("utf") else False)) - print _("Setting new username and password") - print "" from module.DatabaseBackend import DatabaseBackend import module.UserDatabase #register user backend db = DatabaseBackend(None) db.setup() - print "" - username = self.ask(_("Username"), "User") - password = self.ask("", "", password=True) - db.addUser(username, password) + + try: + while True: + print _("Select action") + print _("1 - Create/Edit user") + print _("2 - List users") + print _("3 - Remove user") + action = raw_input("[1]/2/3 ") + if not action in ("1", "2", "3"): + continue + elif action == "1": + print "" + username = self.ask(_("Username"), "User") + password = self.ask("", "", password=True) + db.addUser(username, password) + elif action == "2": + print "" + print _("Users") + print "-----" + users = db.listUsers() + for user in users: + print user + print "-----" + print "" + elif action == "3": + print "" + username = self.ask(_("Username"), "") + if username: + db.removeUser(username) + except KeyboardInterrupt: + print "" #clean + pass db.shutdown() def conf_path(self, trans=False): diff --git a/pyLoadCore.py b/pyLoadCore.py index e08c4c544..6334ca00d 100755 --- a/pyLoadCore.py +++ b/pyLoadCore.py @@ -147,7 +147,7 @@ class Core(object): print " -v, --version", " " * 10, "Print version to terminal" print " -c, --clear", " " * 12, "Delete the saved linklist" #print " -a, --add=<link/list>", " " * 2, "Add the specified links" - print " -u, --user", " " * 13, "Set new User and password" + print " -u, --user", " " * 13, "Manages users" print " -d, --debug", " " * 12, "Enable debug mode" print " -s, --setup", " " * 12, "Run Setup Assistent" print " --configdir=<dir>", " " * 6, "Run with <dir> as config directory" |