def run(self, args): username = args.user password, generated = self.getPassword(args, username) userList = UserList() userList[username].setPassword(DefaultPasswordClass(password), must_change_password=generated) # this is a change to an object in the list, not the list itself # in this case, store() is explicit userList.store()
def run(self, args): username = args.user userList = UserList() # early test to bypass the password stuff if the user already exists if username in userList: raise KeyError("User {username} already exists".format(username=username)) password, generated = self.getPassword(args, username) print("Creating user {username}...".format(username=username)) user = User(name=username, enabled=True, password=DefaultPasswordClass(password), must_change_password=generated) userList.addUser(user)
def run(self, args): userList = UserList() if args.user in userList: if not args.silent: print('User "{name}" exists.'.format(name=args.user)) else: if not args.silent: print('User "{name}" does not exist.'.format(name=args.user)) # in bash, a return code > 0 is interpreted as "false" sys.exit(1)
def processLoginAction(self): data = parse_qs(self.get_body().decode("utf-8")) data = {k: v[0] for k, v in data.items()} userlist = UserList.getSharedInstance() if "user" in data and "password" in data: if data["user"] in userlist: user = userlist[data["user"]] if user.password.is_valid(data["password"]): # TODO evaluate password force_change and redirect to password change key = SessionStorage.getSharedInstance().startSession( {"user": user.name}) cookie = SimpleCookie() cookie["owrx-session"] = key target = self.request.query["ref"][ 0] if "ref" in self.request.query else "/settings" self.send_redirect(target, cookies=cookie) return self.send_redirect("/login")
def getUser(self, request): if "owrx-session" not in request.cookies: return None session_id = request.cookies["owrx-session"].value storage = SessionStorage.getSharedInstance() session = storage.getSession(session_id) if session is None: return None if "user" not in session: return None userList = UserList.getSharedInstance() user = None try: user = userList[session["user"]] storage.prolongSession(session_id) except KeyError: pass return user
def processLoginAction(self): data = parse_qs(self.get_body().decode("utf-8")) data = {k: v[0] for k, v in data.items()} userlist = UserList.getSharedInstance() if "user" in data and "password" in data: if data["user"] in userlist: user = userlist[data["user"]] if user.is_enabled() and user.password.is_valid(data["password"]): key = SessionStorage.getSharedInstance().startSession({"user": user.name}) cookie = SimpleCookie() cookie["owrx-session"] = key target = self.request.query["ref"][0] if "ref" in self.request.query else "/settings" if user.must_change_password: target = "/pwchange?{0}".format(urlencode({"ref": target})) self.set_response_cookies(cookie) self.send_redirect(target) return target = "{}login?{}".format(self.get_document_root(), urlencode({"ref": self.request.query["ref"][0]})) self.send_redirect(target)
def run(self, args): userList = UserList() print("List of enabled users:") for u in userList.values(): if args.all or u.enabled: print(" {name}".format(name=u.name))
def run(self, args): username = args.user userList = UserList() userList[username].enable() userList.store()
def run(self, args): username = args.user print("Deleting user {username}...".format(username=username)) userList = UserList() userList.deleteUser(username)