Esempio n. 1
0
	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=(',',':') ))