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>')
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>')
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>')
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>')
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>')
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)
def test(self): htmlHelper.SetContentTypeToXml(self) self.response.out.write(htmlHelper.XmlDeclaration + '<NothingHere />')