Пример #1
0
    def handleUpdateName(self):
        if "userID" not in self.session:
            self.handle401()
            return

        parts = self.path.split("/")
        nameID = parts[-1]
        length = self.headers["Content-Length"]
        # read the body (data)
        body = self.rfile.read(int(length)).decode("utf-8")
        parsed_body = parse_qs(body)  #decodes encoded data
        name = parsed_body["name"][0]
        gender = parsed_body["gender"][0]
        n = parsed_body["n"][0]
        rank = parsed_body["rank"][0]
        origin = parsed_body["origin"][0]
        fav = parsed_body["fav"][0]
        db = NamesDB()
        nameFound = db.getOneName(nameID)
        if nameFound != None:
            db.updateName(nameID, name, gender, n, rank, origin, fav)

            # respond to the client
            self.send_response(200)
            self.end_headers()
        else:
            self.send404()
Пример #2
0
    def handleDeleteMember(self):
        # Add this to all the methods I don't want to be allowed
        if "userID" not in self.session:
            self.handle401()
            return

        parts = self.path.split("/")
        nameID = parts[-1]
        db = NamesDB()
        name = db.getOneName(nameID)
        if name != None:
            db.deleteOneName(nameID)
            self.send_response(200)
            self.end_headers()
        else:
            self.send404()
Пример #3
0
    def handleNamesRetrieveMember(self):
        if "userID" not in self.session:
            self.handle401()
            return

        #print(self.path)
        parts = self.path.split("/")
        nameID = parts[-1]
        db = NamesDB()
        name = db.getOneName(nameID)
        if name != None:
            self.send_response(200)
            self.send_header("Content-Type", "application/json")
            self.end_headers()
            self.wfile.write(bytes(json.dumps(name), "utf-8"))
        else:
            self.send404()