Exemplo n.º 1
0
    def newUser(self):
        htmlHelper.SetContentTypeToXml(self)
        userName = self.request.get('userName').strip()
        password = self.request.get('password').strip()
        isAdminUser = self.request.get('isAdmin')

        if (len(userName) < 2):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="1">Invalid username</error>')
            return
        if (len(password) < 4):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="2">Invalid password</error>')
            return
        if (datamodule.GetUser(userName, password)):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="3">Username and password already taken</error>'
            )
            return

        user = datamodule.Users(userName=userName,
                                password=password,
                                isAdmin=(True if isAdminUser else False))
        user.put()
        self.response.out.write(htmlHelper.XmlDeclaration +
                                '<OK>User Created</OK>')
Exemplo n.º 2
0
    def addFile(self):
        htmlHelper.SetContentTypeToXml(self)
        currUser = datamodule.GetUser(self.request.get('userName'),
                                      self.request.get('password'))
        if (not currUser):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="4">User not found</error>')
            return

        filename = self.request.get('fileName').strip()

        if len(filename) == 0:
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="5">File name required</error>')
            return

        existingFile = GqlQuery(
            'SELECT __key__ FROM Files WHERE user = :1 AND fileName = :2',
            currUser, filename).get()
        if existingFile:
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="6">File name not unique</error>')
            return

        file = datamodule.Files(user=currUser,
                                fileName=filename,
                                fileText=self.request.get('fileText'))
        file.put()
        self.response.out.write(htmlHelper.XmlDeclaration +
                                '<OK>File Added</OK>')
Exemplo n.º 3
0
 def getUsers(self):
     htmlHelper.SetContentTypeToXml(self)
     users = datamodule.Users.all().fetch(1000, 0)
     self.response.out.write(htmlHelper.XmlDeclaration + '<users>')
     for user in users:
         self.response.out.write('<user userName="******" password="******" isAdmin="' + str(user.isAdmin) + '" />')
     self.response.out.write('</users>')
Exemplo n.º 4
0
    def getFileList(self):
        htmlHelper.SetContentTypeToXml(self)
        user = datamodule.GetUser(self.request.get('userName'),
                                  self.request.get('password'))
        if (not user):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="4">User not found</error>')
            return

        files = datamodule.Files.gql('WHERE user = :1', user).fetch(1000, 0)
        self.response.out.write(htmlHelper.XmlDeclaration + '<files>')
        for file in files:
            self.response.out.write('<file fileName="%s" />' % file.fileName)
        self.response.out.write('</files>')
Exemplo n.º 5
0
    def deleteUser(self):
        htmlHelper.SetContentTypeToXml(self)
        user = datamodule.GetUser(self.request.get('userName'),
                                  self.request.get('password'))
        if (not user):
            self.response.out.write(
                htmlHelper.XmlDeclaration +
                '<error errorId="4">User not found</error>')
            return

        files = GqlQuery('SELECT __key__ FROM Files WHERE user = :1', user)
        db.delete(files.fetch(1000, 0))
        user.delete()
        self.response.out.write(htmlHelper.XmlDeclaration +
                                '<OK>User Deleted</OK>')
Exemplo n.º 6
0
 def getFileText(self):
     htmlHelper.SetContentTypeToXml(self)
     user = datamodule.GetUser(self.request.get('userName'),
                               self.request.get('password'))
     if (not user):
         self.response.out.write(
             htmlHelper.XmlDeclaration +
             '<error errorId="4">User not found</error>')
         return
     file = datamodule.Files.gql('WHERE user = :1 AND fileName = :2', user,
                                 self.request.get('fileName')).get()
     if (not file):
         self.response.out.write(
             htmlHelper.XmlDeclaration +
             '<error errorId="7">File not found</error>')
     else:
         self.response.out.write(file.fileText)
Exemplo n.º 7
0
 def test(self):
     htmlHelper.SetContentTypeToXml(self)
     self.response.out.write(htmlHelper.XmlDeclaration + '<NothingHere />')