def post(self): jsonobject = json.loads(self.request.body) success = False error = 'Invalid request' answer = {} if jsonobject: user_id = int(jsonobject.get('user_id', '')) auth_token = jsonobject.get('auth_token', '') app_secret = jsonobject.get('app_secret', '') if user_id and auth_token and app_secret: if enki.librestapi.check_secret(user_id, auth_token, app_secret): if EnkiModelRestAPITokenVerify.exist_by_user_id_token( user_id, auth_token): friends = enki.libfriends.get_friends_user_id_display_name( user_id) if friends: answer.update({'friends': friends}) success = True error = '' else: error = 'Not found' else: error = 'Unauthorised user' else: error = 'Unauthorised app' answer.update({'success': success, 'error': error}) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps(answer, separators=(',', ':')))
def post( self ): jsonobject = json.loads( self.request.body ) success = False error = 'Invalid request' answer = {} if jsonobject: user_id = int( jsonobject.get( 'user_id', '')) auth_token = jsonobject.get( 'auth_token', '') app_secret = jsonobject.get( 'app_secret', '') products = jsonobject.get( 'products', '') if user_id and auth_token and app_secret: if EnkiModelApp.check_secret( user_id, auth_token, app_secret ): if EnkiModelRestAPITokenVerify.exist_by_user_id_token( user_id, auth_token ): if products: # check which products in the list are activated by the user and return them list_entities = EnkiModelProductKey.fetch_by_activator_products_list( user_id, products ) else: # no product specified, return all products activated by the user list_entities = EnkiModelProductKey.fetch_by_activator( user_id ) if list_entities: list_products = [] for i, item in enumerate( list_entities ): list_products.append( item.product_name ) answer.update({ 'products_owned' : list_products }) success = True error = '' else: error = 'Not found' else: error = 'Unauthorised user' else: error = 'Unauthorised app' answer.update({ 'success' : success, 'error' : error }) self.response.headers[ 'Content-Type' ] = 'application/json' self.response.write( json.dumps( answer, separators=(',',':') ))