def initializeDataBase():
    logger.info("The database name we need to initialize is : %s" % dbname)
    try:
        # 尝试三次创建数据库,如果不成功则提示失败
        for i in range(3):
            logger.info("Try to initialize database attempt times: %s" %
                        int(i + 1))
            # 判断dbUrl中末尾的dbname是否存在,不存在则新建
            logger.info("Whether database %s exists? : %s" %
                        (dbname, database_exists(engine.url)))
            # dbname存在,退出循环
            if database_exists(engine.url):
                break
            if not database_exists(engine.url):
                create_database(engine.url)
                time.sleep(0.1)
                # 判断是否创建成功
                if database_exists(engine.url):
                    logger.info(
                        "Create new database '%s' successfully, dbUrl: %s" %
                        (dbname, dbUrl))
                    logger.info("database_exists(engine.url): %s" %
                                (database_exists(engine.url)))
                    break
        # 3次都没有执行break,说明没创建成功,提示db创建失败
        else:
            logger.info("Create new database '%s' failed" % dbUrl)

    except Exception as e:
        logger.error("initializeDataBase error: %s" % e)
    def get(self, articleIdString):
        try:
            logger.info("articleIdString: %s" % articleIdString)
            # 用正则匹配articleIds=1,2,3中等号后面的部分
            reMatchResult = re.match(r"articleIds=(.*)", articleIdString)
            # 如果匹配到了,说明传了articleIds=部分,继续取articleId
            if reMatchResult:
                articleIdResultString = reMatchResult.group(1)
                logger.info("articleIdResultString: %s" %
                            articleIdResultString)

                # 判断articleIds=后边的id是否有传,传了就把所有的id取出来
                if articleIdResultString:
                    articleIdList = articleIdResultString.split(',')
                    logger.info("articleIdList: %s" % articleIdList)
                    responseDict = {"code": "00", "data": []}
                    blogList = []  # 用于存查询到的blog

                    # 遍历articleIdList,判断每个id是否在db里存在
                    for id in articleIdList:
                        # 校验id值的类型,把字符型转为整形
                        try:
                            idValue = int(id)
                        # 如果不能专属数字,提示不是数字
                        except:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,articleId: %s 不是数字" % id
                            }
                        blog = UserBlog.query.filter(
                            UserBlog.articleId == idValue).first()
                        # 如果这个id有,则把blog对象存到blogList里
                        if blog:
                            blogList.append(blog)
                        # 如果这个id没有,则提示参数值错误
                        else:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,不存在articleId: %s " % id
                            }
                    # 获取到的blog都存到blogList后,把blog填充到responseDict
                    responseDictFilled = util.fillInResponseDict(
                        responseDict, blogList)
                    return responseDictFilled
                # 没有传后边的id,则提示articleId没有传articleIdResultString
                else:
                    return {"code": "02", "message": u"参数值不合法,articleId没有传"}
            # 没匹配到,提示articleIds=没有传值
            else:
                return {"code": "02", "message": u"参数值不合法,articleIds=没有传值"}

        except Exception as e:
            logger.error("error of getBlogContent: %s" % e)
            return {"code": "999", "message": u"未知错误"}
Exemplo n.º 3
0
    def post(self):
        try:
            logger.info("Login -> args.keys(): %s" % self.args.keys())
            userName = self.args['username']
            userPassword = self.args['password']
            neededParams = self.args.keys(
            )  # 记录self.reqparse.add_argument中添加的参数列表
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()  # 记录发送请求中携带的参数列表
            logger.info("requestParams: %s " % requestParams)

            # 判断参数是否都有传过来,都传过来了,并且没有多传或少传,继续做参数值的校验,否则返回“参数错误”
            if userName and userPassword and util.paramsNumResult(
                    neededParams, requestParams):
                #到表里查询,是否存在这个用户,如果存在则校验密码
                userToLogin = User.query.filter(
                    User.username == userName).first()
                logger.info("userToLogin: %s" % userToLogin)

                #判断用户是否存在db中
                if userToLogin:  #如果数据库中有这个user,则校验密码是否正确
                    passwordResult = util.validateMd5Password(
                        userPassword, userName)  # 验证发过来的密码是否和用户存在db里的密码加密后相等
                    if passwordResult:  # 如果密码正确,处理token和loginTime
                        #先把用户的token取出来
                        userTokenInDB = userToLogin.token
                        logger.info("userTokenInDB: %s" % userTokenInDB)
                        #userToken = generateUUID() if not userTokenInDB else generateUUID() #这样更简洁一些
                        # 登录的时候,把数据库里的loginTime和token都做更新
                        userToken = util.generateUUID()
                        userToLogin.token = userToken
                        timeStr = time.strftime("%Y-%m-%d %H:%M:%S")
                        userToLogin.loginTime = timeStr
                        db.session.commit()
                        return {
                            "token": "%s" % userToken,
                            "code": "00",
                            "userid": int(userToLogin.id),
                            "login_time": "%s" % timeStr
                        }
                    else:  #密码不正确
                        return {"code": "02", "message": u"参数值不合法,密码不正确"}
                else:
                    # 数据库中没有这个user
                    return {"code": "02", "message": u"参数值不合法,用户不存在"}

            else:
                return {"code": "03", "message": u"参数错误,可能原因:参数少传了、多传了、写错了"}

        except Exception as e:
            logger.error("error of login: %s" % e)
            return {"code": "999", "message": u"未知错误"}
Exemplo n.º 4
0
    def post(self):
        try:
            logger.info("self.args.keys(): %s" % self.args.keys())
            userName = self.args['username']
            userPassword = self.args['password']
            email = self.args['email']
            neededParams = self.args.keys()
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()
            logger.info("requestParams: %s" % requestParams)

            # 判断参数是否都有传过来,是否多了,是否错了
            if userName and userPassword and email and util.paramsNumResult(
                    neededParams, requestParams):
                userNameResult = util.validateUsername(userName)
                emailResult = util.validateEmail(email)
                passwordResult = util.validatePassword(userPassword)

                #校验各个参数值是否合法
                if userNameResult and emailResult and passwordResult:
                    if not User.query.filter(User.username == userName).all(
                    ):  # 查询数据库里是否存在该username
                        userNew = User(username=userName,
                                       password=userPassword,
                                       email=email)
                        db.session.add(userNew)
                        db.session.commit()
                        return {
                            "code": "00",
                            "userid": userNew.id,
                            "message": u"成功"
                        }
                    else:
                        # 数据库里有重名的
                        return {"code": "01", "message": u"参数值不合法,用户名已存在"}
                else:
                    return {"code": "02", "message": u"参数值不合法,不符合约束条件"}
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、值为空"
                }

        except Exception as e:
            logger.error("error of register: %s" % e)
            return {"code": "999", "message": u"未知错误"}
Exemplo n.º 5
0
def calculateTimeDiff(userLoginTimeStr, timestamp):
    try:
        timestampNew = timestamp
        logger.info("timestampNew : time when post request: %s" % timestampNew)
        timeArray = time.strptime(userLoginTimeStr,
                                  "%Y-%m-%d %H:%M:%S")  # 把userLogin时间字符串转成时间元祖
        logger.info("timeArray after time.strptime func: %s" % str(timeArray))
        timestampOld = time.mktime(timeArray)  # 把时间元祖转换成时间戳
        logger.info("timestampOld format from timeArray: %s" % timestampOld)
        timeStampDiff = timestampNew - timestampOld  # 两个时间戳相减,得出时间差(单位:秒)
        logger.info("timeStampDiff: %s" % timeStampDiff)

        if timeStampDiff > 0:
            timeHourDiff = int(divmod(
                timeStampDiff, 3600)[0])  # 把时间差(秒)换算成小时,处理3600,得到一个元祖,第一个值为小时
            logger.info("the time difference is : %s hour" % timeHourDiff)
            return timeHourDiff
        else:
            logger.error("timestamp different is negative")
            return "wrong"
    except Exception as e:
        logger.error("calculate time difference error: %s" % e)
    def delete(self):
        try:
            logger.info(
                "########################[delete]########################")
            logger.info("self.args.keys(): %s" % self.args.keys())
            json_data = request.get_json(force=True)
            userid = json_data['userid'] if ('userid'
                                             in json_data.keys()) else ""
            logger.info("userid: %s" % userid)
            userToken = json_data['token'] if ('token'
                                               in json_data.keys()) else ""
            logger.info("userToken: %s" % userToken)
            articleIdList = json_data['articleId'] if (
                'articleId' in json_data.keys()) else ""
            logger.info("articleIdList: %s" % articleIdList)
            neededParams = self.args.keys(
            )  # 记录self.reqparse.add_argument中添加的参数列表
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()  # 记录发送请求中携带的参数列表
            logger.info("requestParams: %s" % requestParams)
            requestTimestamp = time.time()

            # 校验是否参数都有传过来,不多不少
            if userid and userToken and articleIdList and util.paramsNumResult(
                    neededParams, requestParams):
                getUserInDB = User.query.filter(User.id == userid).first()
                logger.info("getUserInDB: %s" % getUserInDB)
                # 如果用户存在,继续判断是否有登陆时间和token
                if getUserInDB:
                    userLoginTimeInDB = getUserInDB.loginTime  #取出用户的登录时间
                    logger.info("userLoginTimeInDB: %s" % userLoginTimeInDB)
                    # 获取用户在DB中的token
                    userTokenInDB = getUserInDB.token
                    logger.info("userTokenInDB: %s" % userTokenInDB)
                    # 如果表中有登录时间和token,则继续判断token是否过期
                    if userLoginTimeInDB and userTokenInDB:
                        # 校验登录时间是否超过1小时
                        if util.calculateTimeDiff(userLoginTimeInDB,
                                                  requestTimestamp) >= 1:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,token已过期,请重新登录"
                            }
                        # 登录时间没超过1小时,继续校验token是否和useid是否相匹配
                        else:
                            # 判断token和userid是否相匹配,匹配则处理articleIdList列表
                            if userToken == userTokenInDB:
                                # 判断articleIdList的值是否为列表,是的话,则遍历列表继续处理
                                if type(articleIdList) == list:
                                    logger.info("articleIdList: %s" %
                                                articleIdList)
                                    # 遍历articleId列表
                                    for id in articleIdList:
                                        # 用id去找blog
                                        blog = UserBlog.query.filter(
                                            UserBlog.articleId == id).first()
                                        # 能找到,说明id存在,进行删除动作
                                        if blog:
                                            # 先从db session中删掉,最后一起commit
                                            db.session.delete(blog)

                                        # 没找到,说明id不存在,提示参数值不合法
                                        else:
                                            return {
                                                "code":
                                                "02",
                                                "message":
                                                u"参数值不合法,articleId:%s 不存在" % id
                                            }
                                    # 遍历完articleIdList,id都存在,且都做了删除,则提交commit
                                    db.session.commit()
                                    # 数据库提交删除后,返回结果
                                    return {
                                        "articleId": articleIdList,
                                        "code": "00",
                                        "userid": userid
                                    }

                                # articleId的值不是列表,提示articleId传的不是列表
                                else:
                                    return {
                                        "code": "02",
                                        "message": u"参数值不合法,articleId传的不是列表"
                                    }

                            # token和userid不匹配,说明token不正确,返回参数值不合法,token不正确
                            else:
                                return {
                                    "code": "02",
                                    "message": u"参数值不合法,token不正确"
                                }
                    # 表中没有登录时间和token,提示token不正确,请登录并获取token
                    else:
                        return {
                            "code": "02",
                            "message": u"参数值不合法,token不正确,请登录并获取token"
                        }

                # 如果用户不存在,提示参数值不合法,用户不存在
                else:
                    return {"code": "02", "message": u"参数值不合法,用户不存在"}
            # 参数没传全,或参数写错了,或参数多了
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、参数值为空"
                }

        except Exception as e:
            logger.error("error of delete: %s" % e)
            return {"code": "999", "message": u"未知错误"}
Exemplo n.º 7
0
    def put(self):
        try:
            logger.info(
                "########################[Update]########################")
            logger.info("self.args.keys(): %s" % self.args.keys())
            json_data = request.get_json(force=True)
            logger.info("json_data: %s" % json_data)
            userid = json_data['userid'] if ('userid'
                                             in json_data.keys()) else ""
            logger.info("userid: %s" % userid)
            userToken = json_data['token'] if ('token'
                                               in json_data.keys()) else ""
            logger.info("userToken: %s" % userToken)
            articleId = json_data['articleId'] if ('articleId'
                                                   in json_data.keys()) else ""
            logger.info("articleId: %s" % articleId)
            blogTitle = json_data['title'] if ('title'
                                               in json_data.keys()) else ""
            logger.info("blogTitle: %s" % blogTitle)
            blogContent = json_data['content'] if ('content'
                                                   in json_data.keys()) else ""
            logger.info("blogContent: %s" % blogContent)
            neededParams = self.args.keys(
            )  # 记录self.reqparse.add_argument中添加的参数列表
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()  # 记录发送请求中携带的参数列表
            logger.info("requestParams: %s" % requestParams)
            requestTimestamp = time.time()

            # 校验是否参数都有传过来,不多不少
            if userid and userToken and blogTitle and blogContent and articleId and util.paramsNumResult(
                    neededParams, requestParams):
                getUserInDB = User.query.filter(User.id == userid).first()
                logger.info("getUserInDB: %s" % getUserInDB)
                # 如果用户存在,判断表中是否有登录时间和token
                if getUserInDB:
                    userLoginTimeInDB = getUserInDB.loginTime  #取出用户的登录时间
                    logger.info("userLoginTimeInDB: %s" % userLoginTimeInDB)
                    # 获取用户在DB中的token
                    userTokenInDB = getUserInDB.token
                    logger.info("userTokenInDB: %s" % userTokenInDB)
                    # 如果有登录时间和token,则继续校验token是否过期
                    if userLoginTimeInDB and userTokenInDB:
                        # 校验登录时间是否超过1小时
                        if util.calculateTimeDiff(userLoginTimeInDB,
                                                  requestTimestamp) >= 1:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,token已过期,请重新登录"
                            }
                        # 登录时间没超过1小时,继续校验token是否和useid是否相匹配
                        else:
                            # 判断token和userid是否相匹配,匹配则继续检验articleId是否存在
                            if userToken == userTokenInDB:
                                # 判断artileId是否在DB中存在
                                getBlogInDB = UserBlog.query.filter(
                                    UserBlog.articleId == articleId).first()
                                logger.info("getBlogInDB: %s" % getBlogInDB)
                                # 如果用articleId能查到博文,存表(update_time,title, content),并返回
                                if getBlogInDB:
                                    # 先获取到更新博文的时间
                                    updateBlogTimeString = time.strftime(
                                        "%Y-%m-%d %H:%M:%S",
                                        time.localtime(requestTimestamp))
                                    logger.info("updateBlogTimeString: %s" %
                                                updateBlogTimeString)

                                    # 存表: blogTitle、blogContent、updateTime
                                    updateBlog = UserBlog.query.filter(
                                        UserBlog.articleId ==
                                        articleId).first()
                                    updateBlog.updateTime = updateBlogTimeString
                                    updateBlog.blogTitle = blogTitle
                                    updateBlog.blogContent = blogContent
                                    db.session.commit()
                                    # 返回成功
                                    return {
                                        "articleId": articleId,
                                        "update_time": updateBlogTimeString,
                                        "code": "00",
                                        "userid": userid
                                    }
                                # 如果用articleId查不到博文,则提示参数值不合法,articleId不存在
                                else:
                                    return {
                                        "code": "02",
                                        "message": u"参数值不合法,articleId不存在"
                                    }

                            # token和userid不匹配,说明token不正确,返回参数值不合法,token不正确
                            else:
                                return {
                                    "code": "02",
                                    "message": u"参数值不合法,token不正确"
                                }

                    # 如果没有登录时间和token,则提示token不正确,请登录并获取token
                    else:
                        return {
                            "code": "02",
                            "message": u"参数值不合法,token不正确,请登录并获取token"
                        }

                        # 如果用户不存在,提示参数值不合法,用户不存在
                else:
                    return {"code": "02", "message": u"参数值不合法,用户不存在"}
            # 参数没传全,或参数写错了,或参数多了
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、值为空"
                }

        except Exception as e:
            logger.error("error of update: %s" % e)
            return {"code": "999", "message": u"未知错误"}
    def post(self):
        try:
            userid = self.args['userid']
            userToken = self.args['token']
            offset = self.args['offset']
            lines = self.args['lines']
            neededParams = self.args.keys(
            )  # 记录self.reqparse.add_argument中添加的参数列表
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()  # 记录发送请求中携带的参数列表
            logger.info("requestParams: %s" % requestParams)
            requestTimestamp = time.time()
            logger.info("type(offset) -> %s \n type(lines) -> %s" %
                        (type(offset), type(lines)))

            # 校验是否参数都有传过来(除了offset和lines),不多不少
            if userid and userToken and util.paramsNumResult(
                    neededParams, requestParams):
                getUserInDB = User.query.filter(User.id == userid).first()
                logger.info("getUserInDB: %s" % getUserInDB)
                # 如果用户存在,判断登录时间是否超过一小时
                if getUserInDB:
                    userLoginTime = getUserInDB.loginTime  #取出用户的登录时间
                    logger.info("userLoginTime: %s" % userLoginTime)
                    # 校验登录时间是否超过1小时
                    if util.calculateTimeDiff(userLoginTime,
                                              requestTimestamp) >= 1:
                        return {
                            "code": "02",
                            "message": u"参数值不合法,token已过期,请重新登录"
                        }
                    # 登录时间没超过1小时,继续校验token是否和useid是否相匹配
                    else:
                        # 获取用户在DB中的token
                        userTokenInDB = getUserInDB.token
                        logger.info("userTokenInDB: %s" % userTokenInDB)
                        # 判断token和userid是否相匹配,匹配则处理offset和lines逻辑
                        if userToken == userTokenInDB:
                            # 定义一个临时字典
                            responseDict = {
                                "data": [],
                                "code": "00",
                                "userid": userid
                            }
                            userOfBlog = User.query.filter(
                                User.id == userid).first()
                            blogs = userOfBlog.blogs
                            logger.info("blogs: %s" % blogs)
                            # 如果用户有博文,则继续,否则直接返回responseDict
                            if blogs:
                                # 如果offset和lines都传了则继续校验offset和lines的值
                                if offset and lines:
                                    # 判断博文数是否够跳offset条,够跳,继续判断是否够返回lines条数据
                                    if len(blogs) > int(offset):
                                        # 跳过offset够取lines条数据,返回跳过offset条后,lines条数据:blogs[offset : (offset + lines + 1)],包含第lines条
                                        if (len(blogs) -
                                                int(offset)) > int(lines):
                                            blogsAfterJumpOffsetGetLines = blogs[
                                                int(offset):(int(offset) +
                                                             int(lines))]
                                            logger.info(
                                                "blogsAfterJumpOffsetGetLines : %s"
                                                % blogsAfterJumpOffsetGetLines)
                                            responseDictFilled = util.fillInResponseDict(
                                                responseDict,
                                                blogsAfterJumpOffsetGetLines)
                                            return responseDictFilled
                                        # 跳过offset不够取lines条数据,返回跳过offset条后所有的blog:blogs[offset : ]
                                        else:
                                            blogsAfterJumpOffset = blogs[
                                                int(offset):]
                                            logger.info(
                                                "blogsAfterJumpOffset: %s" %
                                                blogsAfterJumpOffset)
                                            responseDictFilled = util.fillInResponseDict(
                                                responseDict,
                                                blogsAfterJumpOffset)
                                            return responseDictFilled

                                    # 博文数不够跳offset条,则返回博文列表为空
                                    else:
                                        return responseDict
                                # offset和lines没有都传过来,则返回用户全部博文
                                else:
                                    responseDictFilled = util.fillInResponseDict(
                                        responseDict, blogs)
                                    return responseDictFilled
                            # 没有博文,直接返回,"data"列表为空
                            else:
                                return responseDict

                        # token和userid不匹配,说明token不正确,返回参数值不合法,token不正确
                        else:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,token不正确"
                            }
                # 如果用户不存在,提示参数值不合法,用户不存在
                else:
                    return {"code": "02", "message": u"参数值不合法,用户不存在"}
            # 参数没传全,或参数写错了,或参数多了
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、值为空"
                }

        except Exception as e:
            logger.error("error of update: %s" % e)
            return {"code": "999", "message": u"未知错误"}
    def post(self):
        try:
            logger.info(
                "########################[Register]########################")
            logger.info("self.args.keys(): %s" % self.args.keys())
            json_data = request.get_json(force=True)
            logger.info("json_data: %s" % json_data)
            userName = json_data['username'] if ('username'
                                                 in json_data.keys()) else ""
            #userName = self.args['username']
            logger.info("username: %s" % userName)
            #userPassword = sel.args['password']
            userPassword = json_data['password'] if (
                'password' in json_data.keys()) else ""
            logger.info("userPassword: %s" % userPassword)
            email = json_data['email'] if ('email' in json_data.keys()) else ""
            #email = self.args['email']
            logger.info("email: %s" % email)
            neededParams = self.args.keys()
            logger.info("neededParams: %s" % neededParams)
            logger.info("#####request: %s " % request)
            logger.info("#####request.json: %s " % request.json)
            logger.info("#####dir(request): %s " % dir(request))
            logger.info("#####request.host: %s " % request.host)
            logger.info("#####request.headers: %s " % request.headers)
            logger.info("#####request.endpoint: %s " % request.endpoint)
            logger.info("#####request.data: %s " % request.data)
            logger.info("#####request.content_type: %s " %
                        request.content_type)
            logger.info("#####request.form: %s " % request.form)
            requestParams = request.json.keys()
            logger.info("requestParams: %s" % requestParams)

            # 判断参数是否都有传过来,是否多了,是否错了
            if userName and userPassword and email and util.paramsNumResult(
                    neededParams, requestParams):
                #if userName and userPassword and email:
                userNameResult = util.validateUsername(userName)
                emailResult = util.validateEmail(email)
                passwordResult = util.validatePassword(userPassword)

                #校验各个参数值是否合法
                if userNameResult and emailResult and passwordResult:
                    if not User.query.filter(User.username == userName).all(
                    ):  # 查询数据库里是否存在该username
                        userNew = User(username=userName,
                                       password=userPassword,
                                       email=email)
                        db.session.add(userNew)
                        db.session.commit()
                        return {
                            "code": "00",
                            "userid": userNew.id,
                            "message": u"成功"
                        }
                    else:
                        # 数据库里有重名的
                        return {"code": "01", "message": u"参数值不合法,用户名已存在"}
                else:
                    return {"code": "02", "message": u"参数值不合法,不符合约束条件"}
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、参数值为空"
                }

        except Exception as e:
            logger.error("error of register: %s" % e)
            return {"code": "999", "message": u"未知错误"}
Exemplo n.º 10
0
    def post(self):
        try:
            userid = self.args['userid']
            userToken = self.args['token']
            articleId = self.args['articleId']
            blogTitle = self.args['title']
            blogContent = self.args['content']
            neededParams = self.args.keys(
            )  # 记录self.reqparse.add_argument中添加的参数列表
            logger.info("neededParams: %s" % neededParams)
            requestParams = request.json.keys()  # 记录发送请求中携带的参数列表
            logger.info("requestParams: %s" % requestParams)
            requestTimestamp = time.time()

            # 校验是否参数都有传过来,不多不少
            if userid and userToken and blogTitle and blogContent and articleId and util.paramsNumResult(
                    neededParams, requestParams):
                getUserInDB = User.query.filter(User.id == userid).first()
                logger.info("getUserInDB: %s" % getUserInDB)
                # 如果用户存在,判断登录时间是否超过一小时
                if getUserInDB:
                    userLoginTime = getUserInDB.loginTime  #取出用户的登录时间
                    logger.info("userLoginTime: %s" % userLoginTime)
                    # 校验登录时间是否超过1小时
                    if util.calculateTimeDiff(userLoginTime,
                                              requestTimestamp) >= 1:
                        return {
                            "code": "02",
                            "message": u"参数值不合法,token已过期,请重新登录"
                        }
                    # 登录时间没超过1小时,继续校验token是否和useid是否相匹配
                    else:
                        # 获取用户在DB中的token
                        userTokenInDB = getUserInDB.token
                        logger.info("userTokenInDB: %s" % userTokenInDB)
                        # 判断token和userid是否相匹配
                        if userToken == userTokenInDB:
                            # 判断artileId是否在DB中存在
                            getBlogInDB = UserBlog.query.filter(
                                UserBlog.articleId == articleId).first()
                            logger.info("getBlogInDB: %s" % getBlogInDB)
                            # 如果用articleId能查到博文,存表(update_time,title, content),并返回
                            if getBlogInDB:
                                # 先获取到更新博文的时间
                                updateBlogTimeString = time.strftime(
                                    "%Y-%m-%d %H:%M:%S",
                                    time.localtime(requestTimestamp))
                                logger.info("updateBlogTimeString: %s" %
                                            updateBlogTimeString)

                                #存表: blogTitle、blogContent、updateTime
                                updateBlog = UserBlog.query.filter(
                                    UserBlog.articleId == articleId).first()
                                updateBlog.updateTime = updateBlogTimeString
                                updateBlog.blogTitle = blogTitle
                                updateBlog.blogContent = blogContent
                                db.session.commit()
                                # 返回成功
                                return {
                                    "articleId": articleId,
                                    "update_time": updateBlogTimeString,
                                    "code": "00",
                                    "userid": userid
                                }
                            # 如果用articleId查不到博文,则提示参数值不合法,articleId不存在
                            else:
                                return {
                                    "code": "02",
                                    "message": u"参数值不合法,articleId不存在"
                                }

                        # token和userid不匹配,说明token不正确,返回参数值不合法,token不正确
                        else:
                            return {
                                "code": "02",
                                "message": u"参数值不合法,token不正确"
                            }
                # 如果用户不存在,提示参数值不合法,用户不存在
                else:
                    return {"code": "02", "message": u"参数值不合法,用户不存在"}
            # 参数没传全,或参数写错了,或参数多了
            else:
                return {
                    "code": "03",
                    "message": u"参数错误,可能原因:参数少传了、多传了、写错了、值为空"
                }

        except Exception as e:
            logger.error("error of update: %s" % e)
            return {"code": "999", "message": u"未知错误"}