def post(self): self.response.headers['Access-Control-Allow-Origin'] = '*' userID, displayName = self.determine_user() usr = db_api.getUser(userID) if not usr: usr = db_api.newUser(userID, displayName) r = {'userID': userID, 'displayName': displayName} self.response.write(tojson(r) + '\n')
def post(self, fcn): logging.info('%s ...' % self.request.url) if not fcn: fcn = self.request.get('fcn') if fnc: # TODO remove once there are no more uses of ?fcn=... in our code logging.warning('Please use /grits/%s/?foo=... instead of /grits/?fcn=%s&foo=...' % (fnc, fnc)) self.response.headers['Access-Control-Allow-Origin'] = '*' userID, displayName = self.determine_user() usr = db_api.getUser(userID) if not usr: if userID.startswith('bot*'): usr = db_api.newUser(userID, displayName) else: self.response.set_status(404) self.response.write('Grits userID not found: ' + userID) return if fcn == 'getProfile': r = {'userID': userID, 'credits': str(usr.credits), 'numWins': str(usr.numWins), 'virtualItems': usr.virtualItems} self.response.write(tojson(r)) elif fcn == 'getFriends': self.getFriends(userID) elif fcn == 'buyItem': itemID = self.request.get('itemID') if not itemID: self.response.set_status(400) self.response.write('Grits itemID is required') return r = db_api.userAttemptToBuy(userID, itemID) self.response.write(tojson(r)) elif fcn == 'findGame': self.findGame(userID) else: self.response.set_status(400) self.response.write('Bad grits request.')