Beispiel #1
0
    def do_GET(self):
        #index or list action
        self.load_session()

        if self.path.startswith("/contacts/"):
            #handle specific contact
            lst = ContactsDB()
            usr = UserDB()
            matched = False
            allUsers = usr.getUsernames()
            for i in allUsers:
                if gSessionStore.sessionData[
                        self.session] == i[0] and i[0] != "":
                    matched = True
                    break
                else:
                    matched = False
            print(matched)
            if matched:
                idPath = self.path
                contact = lst.getContact(idPath)
                if len(contact) == 2:
                    self.header404("Couldn't find contact")
                else:
                    self.header200()
                    self.wfile.write(bytes(contact, "utf-8"))
            else:
                self.header401()
        elif self.path.startswith("/contacts"):
            #handle contacts
            lst = ContactsDB()
            usr = UserDB()
            matched = False
            allUsers = usr.getUsernames()
            for i in allUsers:
                if gSessionStore.sessionData[
                        self.session] == i[0] and i[0] != "":
                    matched = True
                    break
                else:
                    matched = False
            print(matched)
            if matched:
                contacts = lst.getContacts()
                self.header200()
                self.wfile.write(bytes(contacts, "utf-8"))
            else:
                self.header401()
        else:
            self.header404("Collection not found")
Beispiel #2
0
 def do_GET(self):
     #index or list action
     lst = ContactsDB()
     if self.path.startswith("/contacts/"):
         idPath = self.path
         contact = lst.getContact(idPath)
         if len(contact) == 2:
             self.header404()
         else:
             self.header200()
             self.wfile.write(bytes(contact, "utf-8"))
     elif self.path.startswith("/contacts"):
         #handle contacts
         contacts = lst.getContacts()
         self.header200()
         self.wfile.write(bytes(contacts, "utf-8"))
     else:
         self.header404()