handlersrestapi.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:enkiWS 作者: juliettef 项目源码 文件源码
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', '')
            data_type = jsonobject.get( 'data_type', '')
            data_id = jsonobject.get( 'data_id', '')
            if user_id and auth_token and app_secret and data_type and data_id:
                if EnkiModelApp.check_secret( user_id, auth_token, app_secret ):
                    token_valid = EnkiModelRestAPITokenVerify.get_by_user_id_token( user_id, auth_token )
                    if token_valid:   # user is valid
                        data_stores = EnkiModelRestAPIDataStore.fetch_by_user_id_app_id_data_type_data_id( user_id, token_valid.app_id, data_type, data_id )
                        ndb.delete_multi( data_stores )
                        success = True
                        error = ''
                    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=(',',':') ))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号