Example #1
0
def get(data):
    #必须要的信息
    requireList = ['newCatalog']
    #返回的信息
    message = ''
    result = False
    newsList = []
    #查看是否存在用户
    if checkItem(data, requireList):
        newsQueryCondition = {'newCatalog': data['newCatalog']}
        #get news

        for news in News.find(newsQueryCondition):
            print news
            newsList.append({
                "newCatalog": news["newCatalog"],
                "newsTime": news["newTime"],
                "newHref": news["newHref"],
                "newContent": news["newContent"]
                })
        if len(newsList) != 0:
            result = True
            message = 'no user'
        else:
            newsList = []
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'news': newsList
    }
Example #2
0
def add(data):
    #必须带有的参数
    requireList = ['newTitle', 'newContent', 'newHref', 'newCatalog', 'newTime']
    #返回的信息
    message = ''
    result = False
    user = {}
    #首先检查是否存在标题、内容、链接、时间和分类
    if checkItem(data, requireList):
        addNew = {
            'uuid': uuid.uuid1().hex,
            'newTitle': data['newTitle'],
            'newContent': data['newContent'],
            'newTime': data['newTime'],
            'newHref':data['newHref'],
            'newCatalog': data['newCatalog'],
        }
        News.insert(addNew)
        result = True
    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {
        'uuid': addNew.get('uuid', ''),
        'result': result,
        'message': message,
    }
Example #3
0
def update(data):
    #必须带有的参数
    requireList = ['newCatalog']
    #返回的信息
    message = ''
    result = False
    #是否存在
    if checkItem(data, requireList):
        newsQueryCondition = {'newCatalog': data['newCatalog']}
        delResult = News.delete_many(newsQueryCondition)
        if delResult.acknowledged:
            if len(data['newsList']) > 0:
                addResult = News.insert_many(data['newsList'])
                if addResult.acknowledged:
                    result = True
                else:
                    message = 'insert new post fail'
            else:
                result = True
                message = 'no insert'
        else:
            message = 'delete old record fail'
            result = False
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
    }
Example #4
0
def update(data):
    #必须带有的参数
    requireList = ['newCatalog']
    #返回的信息
    message = ''
    result = False
    #是否存在
    if checkItem(data, requireList):
        newsQueryCondition = {'newCatalog': data['newCatalog']}
        delResult = News.delete_many(newsQueryCondition)
        if delResult.acknowledged:
            if len(data['newsList']) > 0:
                for item in data['newsList']:
                    item['uuid'] = uuid.uuid1().hex
                addResult = News.insert_many(data['newsList'])
                if addResult.acknowledged:
                    result = True
                else:
                    message = 'insert new post fail'
            else:
                result = True
                message = 'no insert'
        else:
            message = 'delete old record fail'
            result = False
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
    }
Example #5
0
def get(data):
    #必须要的信息
    requireList = ['newCatalog']
    #返回的信息
    message = ''
    result = False
    newsList = []
    #查看是否存在用户
    if checkItem(data, requireList):
        newsQueryCondition = {'newCatalog': data['newCatalog']}
        #get news
        for news in News.find(newsQueryCondition):
            newsList.append({
                "uuid": news["uuid"],
                "newCatalog": news["newCatalog"],
                "newTime": news["newTime"],
                "newHref": news["newHref"],
                "newTitle": news["newTitle"]
            })
        if len(newsList) != 0:
            result = True
            message = 'no user'
        else:
            newsList = []
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {'result': result, 'message': message, 'news': newsList}
Example #6
0
def getContent(data):
    #必须要的信息
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    newsContent = ''
    findNews = {}
    #查看是否存在用户
    if checkItem(data, requireList):
        newsQueryCondition = {'uuid': data['uuid']}
        #get news
        findNews = News.find_one(newsQueryCondition)
        if findNews != {}:
            newsContent = findNews.get('newContent', '')
        else:
            newContent = ''
        result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'newsContent': newsContent,
        'newTitle': findNews.get('newTitle', ''),
        'newTime': findNews.get('newTime', ''),
        'newCatalog': findNews.get('newCatalog', '')
    }
Example #7
0
def add(data):
    #必须带有的参数
    requireList = [
        'newTitle', 'newContent', 'newHref', 'newCatalog', 'newTime'
    ]
    #返回的信息
    message = ''
    result = False
    user = {}
    #首先检查是否存在标题、内容、链接、时间和分类
    if checkItem(data, requireList):
        addNew = {
            'uuid': uuid.uuid1().hex,
            'newTitle': data['newTitle'],
            'newContent': data['newContent'],
            'newTime': data['newTime'],
            'newHref': data['newHref'],
            'newCatalog': data['newCatalog'],
        }
        News.insert(addNew)
        result = True
    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {
        'uuid': addNew.get('uuid', ''),
        'result': result,
        'message': message,
    }
Example #8
0
def get(data):
    #必须要的信息
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    user = {}
    #查看是否存在用户
    if checkItem(data, requireList):
        userQueryCondition = {'uuid': data['uuid']}
        #get user
        user = Users.find_one(userQueryCondition)
        if user is None:
            result = False
            message = 'no user'
        else:
            #删除敏感信息
            del user['password']
            del user['_id']
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'user': user
    }
Example #9
0
def getContent(data):
    #必须要的信息
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    newsContent = ''
    findNews = {}
    #查看是否存在用户
    if checkItem(data, requireList):
        newsQueryCondition = {'uuid': data['uuid']}
        #get news
        findNews = News.find_one(newsQueryCondition)
        if findNews != {}:
            newsContent = findNews.get('newContent', '')
        else:
            newContent = ''
        result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'newsContent': newsContent,
        'newTitle': findNews.get('newTitle', ''),
        'newTime': findNews.get('newTime', ''),
        'newCatalog': findNews.get('newCatalog', '')
}
Example #10
0
def get(data):
    #必须要的信息
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    user = {}
    #查看是否存在用户
    if checkItem(data, requireList):
        userQueryCondition = {'uuid': data['uuid']}
        #get user
        user = Users.find_one(userQueryCondition)
        if user is None:
            result = False
            message = 'no user'
        else:
            #删除敏感信息
            del user['password']
            del user['_id']
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {'result': result, 'message': message, 'user': user}
Example #11
0
def login(data):
    #必须带有的参数
    requireList = ['loginID', 'password']
    #返回的信息
    message = ''
    result = False
    uuid = ""
    user = {}
    #首先检查是否存在loginID 和 password
    if checkItem(data, requireList):
        #检查是否存在的相同的loginID
        queryCondition = {'loginID': data['loginID']}
        user = Users.find_one(queryCondition)
        if user is None:
            result = False
            message = 'no user exist'
        else:
            if data['loginID'] == user['loginID'] and \
            hashlib.sha1(data['password']).hexdigest() == user['password']:
                uuid = user["uuid"]
                #删除敏感信息
                del user['password']
                del user['_id']
                result = True
            else:
                user = {}#if password is wrong, clear user. Not to return the uuid.
                result = False
                message = 'loginID or password error'

    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {
        'result': result,
        'message': message,
        'uuid': uuid,
        'user': user
    }
Example #12
0
def register(data):
    #必须带有的参数
    requireList = ['loginID', 'password']
    #返回的信息
    message = ''
    result = False
    user = {}
    #首先检查是否存在loginID 和 password
    if checkItem(data, requireList):
        #检查是否存在的相同的loginID
        queryCondition = {'loginID': data['loginID']}
        user = Users.find_one(queryCondition)
        if user is not None:
            user = {}#if user is found, clear user. Not to return the uuid.
            result = False
            message = 'loginID has been used!'
        else:
            #开始加入数据库
            newUser = {
                'uuid': uuid.uuid1().hex,
                'loginID': data['loginID'],
                'password': hashlib.sha1(data['password']).hexdigest(),
                'name': data.get('name', ''),
                'subscribe': data.get('subscribe', []),
                'email': data.get('email', ''),
            }
            Users.insert(newUser)
            user = newUser
            result = True

    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {
        'uuid': user.get('uuid', ''),
        'result': result,
        'message': message,
    }
Example #13
0
def register(data):
    #必须带有的参数
    requireList = ['loginID', 'password']
    #返回的信息
    message = ''
    result = False
    user = {}
    #首先检查是否存在loginID 和 password
    if checkItem(data, requireList):
        #检查是否存在的相同的loginID
        queryCondition = {'loginID': data['loginID']}
        user = Users.find_one(queryCondition)
        if user is not None:
            user = {}  #if user is found, clear user. Not to return the uuid.
            result = False
            message = 'loginID has been used!'
        else:
            #开始加入数据库
            newUser = {
                'uuid': uuid.uuid1().hex,
                'loginID': data['loginID'],
                'password': hashlib.sha1(data['password']).hexdigest(),
                'name': data.get('name', ''),
                'subscribe': data.get('subscribe', []),
                'email': data.get('email', ''),
            }
            Users.insert(newUser)
            user = newUser
            result = True

    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {
        'uuid': user.get('uuid', ''),
        'result': result,
        'message': message,
    }
Example #14
0
def update(data):
    #必须带有的参数
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    user = {}
    #是否存在用户
    if checkItem(data, requireList):
        userQueryCondition = {'uuid': data['uuid']}
        user = Users.find_one(userQueryCondition)
        if user is None:
            result = False
            message = 'no user'
        else:
            #不更新uuid
            del data['uuid']
            #更新密码
            if data.get('password', '') != '':
                data['password'] = hashlib.sha1(data['password']).hexdigest()
            else:
                del data['password']
            Users.update({'uuid': user['uuid']}, {"$set": data})
            user = Users.find_one(userQueryCondition)
            #删除敏感信息
            del user['password']
            del user['_id']
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'user': user,
    }
Example #15
0
def update(data):
    #必须带有的参数
    requireList = ['uuid']
    #返回的信息
    message = ''
    result = False
    user = {}
    #是否存在用户
    if checkItem(data, requireList):
        userQueryCondition = {'uuid': data['uuid']}
        user = Users.find_one(userQueryCondition)
        if user is None:
            result = False
            message = 'no user'
        else:
            #不更新uuid
            del data['uuid']
            #更新密码
            if data.get('password', '') != '':
                data['password'] = hashlib.sha1(data['password']).hexdigest()
            else:
                del data['password']
            Users.update({'uuid': user['uuid']}, {"$set": data})
            user = Users.find_one(userQueryCondition)
            #删除敏感信息
            del user['password']
            del user['_id']
            result = True
    else:
        #没有足够参数
        result = False
        message = 'not enough params'
    return {
        'result': result,
        'message': message,
        'user': user,
    }
Example #16
0
def login(data):
    #必须带有的参数
    requireList = ['loginID', 'password']
    #返回的信息
    message = ''
    result = False
    uuid = ""
    user = {}
    #首先检查是否存在loginID 和 password
    if checkItem(data, requireList):
        #检查是否存在的相同的loginID
        queryCondition = {'loginID': data['loginID']}
        user = Users.find_one(queryCondition)
        if user is None:
            result = False
            message = 'no user exist'
        else:
            if data['loginID'] == user['loginID'] and \
            hashlib.sha1(data['password']).hexdigest() == user['password']:
                uuid = user["uuid"]
                #删除敏感信息
                del user['password']
                del user['_id']
                result = True
            else:
                user = {
                }  #if password is wrong, clear user. Not to return the uuid.
                result = False
                message = 'loginID or password error'

    else:
        #没有足够的参数
        result = False
        message = 'not enough params'
    #返回出去
    return {'result': result, 'message': message, 'uuid': uuid, 'user': user}