diff options
Diffstat (limited to 'module')
-rw-r--r-- | module/UserDatabase.py | 17 | ||||
-rw-r--r-- | module/setup.py | 38 |
2 files changed, 49 insertions, 6 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): |