コード例 #1
0
    def HandleUserCreation(self):
        length = int(self.headers["Content-length"])
        body = self.rfile.read(length).decode("utf-8")
        parsed_body = parse_qs(body)
        db = CarsDB()

        fname = parsed_body['fname'][0]
        lname = parsed_body['lname'][0]
        email = parsed_body['email'][0]
        password = parsed_body['password'][0]

        user = db.getUserbyEmail(email)

        if user == None:

            db.createUser(fname, lname, email, password)

            self.send_response(201)
            self.end_headers()
            self.wfile.write(bytes("Created", "utf-8"))

        else:
            self.Handle422()
コード例 #2
0
    def HandleSessionCreation(self):
        length = int(self.headers["Content-length"])
        body = self.rfile.read(length).decode("utf-8")
        parsed_body = parse_qs(body)
        db = CarsDB()

        email = parsed_body['email'][0]
        password = parsed_body['password'][0]

        user = db.getUserbyEmail(email)
        if user != None:
            print(user)
            if bcrypt.verify(password, user["encrypted_password"]) == True:
                self.session["userId"] = user["id"]
                self.send_response(201)
                self.send_cookie()
                self.end_headers()
                self.wfile.write(bytes(json.dumps(user), "utf-8"))
            else:
                self.Handle401()
        else:
            self.Handle401()

        return