Example #1
0
def post_Article():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    params = request.get_json()
    if 'title' in params and 'brief' in params and 'body' in params:
        #先将内容保存成文件,然后将地址等信息上传到数据库
        filePath = FileApi.generateFilePath(
            ''.join([
                random.choice(string.digits + string.ascii_letters)
                for i in range(5)
            ]) + '.md', "articles/bodys/" + userid)
        absFilePath = os.path.join(config.STATIC_FILE_PATH, filePath)
        if FileApi.saveFile(absFilePath, params['body'])['status']:
            return jsonify(
                ArticleApi.postArticle(userid, params['title'],
                                       params['brief'], params["keywords"],
                                       params["coverurl"], filePath))
        else:
            return jsonify(Common.falseReturn(None, 'file save failure!'))
    else:
        return jsonify(
            Common.falseReturn(
                None,
                'Please make sure {"title":a,"breif":a,"keywords":a,"body":a}')
        )
Example #2
0
def update_UserIntroduceTag():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    params = request.get_json()
    if 'tags' in params:
        return jsonify(IntroduceApi.changeTags(userid, params['tags']))
    return jsonify(Common.falseReturn(None, 'tags is needed'))
Example #3
0
def change_username():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    params = request.get_json()
    if not params.get('username'):
        return jsonify(Common.falseReturn(None, 'username cannot be empty'))
    return jsonify(UserApi.updateUserName(userid, params.get('username')))
Example #4
0
def add_commentLikes():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    params = request.get_json()
    if 'commentid' in params:
        return jsonify(LikesApi.postLikesComment(params['commentid'], userid))
    return jsonify(Common.falseReturn(None, 'commentid in json is needed'))
Example #5
0
def add_ArticleBrowser():
    articleid = None
    params = request.get_json()
    if 'articleid' in params:
        articleid = params['articleid']
    else:
        return jsonify(Common.falseReturn(None, 'articleid is required'))
    userid = IdentifyUtil.get_user_id()
    return jsonify(
        BrowserApi.postArticleBrowser(articleid, userid, request.remote_addr))
Example #6
0
def delete_Comments(commentid):
    #获取自己id,只能删除自己文章下或者自己的评论
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    if CommentApi.getIsSelfComment(
            userid, commentid)['data'] or CommentApi.getIsSelfArticlesComment(
                userid, commentid)['data']:
        return jsonify(CommentApi.deleteComment(commentid))
    return jsonify(Common.falseReturn(None, 'permission denied'))
Example #7
0
def update_UserIntroduce():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    params = request.get_json()
    if 'resume' in params and 'tags' in params:
        return jsonify(
            IntroduceApi.changeIntroduce(userid, params['resume'],
                                         params['tags']))
    return jsonify(Common.falseReturn(None, 'add error'))
Example #8
0
def post_Comments():
    '''需要提供articleid,comment,refid'''
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    params = request.get_json()
    if 'articleid' not in params or 'comment' not in params:
        return jsonify(Common.falseReturn('articleid and comment is required'))
    res = CommentApi.postComment(params.get('articleid'), userid,
                                 params.get('comment'), params.get('refid'))
    return jsonify(res)
Example #9
0
def update_Comments(commentid):
    #获取自己id,只能修改自己的评论
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    params = request.get_json()
    if 'comment' not in params:
        return jsonify(Common.falseReturn(None, 'comment is required'))
    if not CommentApi.getIsSelfComment(userid, commentid)['data']:
        return jsonify(Common.falseReturn(None, 'permission denied'))
    return jsonify(
        CommentApi.updateCommentByCommentId(commentid, params.get('comment')))
Example #10
0
def post_article_file_Services(fileName):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    '''上传功能'''
    refPath = FileApi.generateFilePath(fileName, "articles/pictures/" + userid)
    uploadPath = os.path.join(config.STATIC_FILE_PATH, refPath)

    saveResult = FileApi.saveRequestFileWithPath(uploadPath, request)
    if saveResult['status']:
        return jsonify(Common.trueReturn({'filepath': refPath}, 'up ok'))
    else:
        return jsonify(saveResult)
Example #11
0
def change_userpassword():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    params = request.get_json()
    if not params.get('oldpassword') or not params.get('newpassword'):
        return jsonify(
            Common.falseReturn(None,
                               'newpassword or oldpassword cannot be empty'))
    user = UserApi.getUserBase(userid)
    if user['status'] and user['data'].get(
            'password') == IdentifyUtil.hash_secret(params.get('oldpassword')):
        return jsonify(
            UserApi.updateUserPassword(userid, params.get('newpassword')))
    return jsonify(Common.falseReturn(None, 'check old password wrong'))
Example #12
0
def delete_Article(articleid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    #判定是否是自己的文章,否则不能删除
    articleBase = ArticleApi.getArticleBaseByID(articleid)
    if not articleBase['status']:
        return jsonify(Common.falseReturn(None, 'article not found'))
    if userid != articleBase['data']['userid']:
        return jsonify(Common.falseReturn(None, "it's not your article"))
    try:
        os.remove(
            os.path.join(config.STATIC_FILE_PATH,
                         articleBase['data']['bodyurl']))
    except Exception as e:
        print(e)
    finally:
        return jsonify(ArticleApi.deleteArticle(articleid))
Example #13
0
def update_Article(articleid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    #判定是否是自己的文章,否则不能修改
    articleBase = ArticleApi.getArticleBaseByID(articleid)
    if not articleBase['status']:
        return jsonify(Common.falseReturn(None, 'article not found'))
    if userid != articleBase['data']['userid']:
        return jsonify(Common.falseReturn(None, "it's not your article"))
    #开始修改文章
    params = request.get_json()
    absFilePath = os.path.join(config.STATIC_FILE_PATH,
                               articleBase['data']['bodyurl'])
    if FileApi.saveFile(absFilePath, params['body']):
        return jsonify(
            ArticleApi.updateArticle(articleid, params['title'],
                                     params['brief'], params["keywords"],
                                     params["coverurl"]))
    return jsonify(Common.falseReturn(None, 'save article file wrong'))
Example #14
0
def get_IsSelfLikeComment(commentid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    return jsonify(LikesApi.getIsSelfLikesComment(userid, commentid))
Example #15
0
def get_IsSelfLikeArticle(articleid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    return jsonify(LikesApi.getIsSelfLikesArticle(userid, articleid))
Example #16
0
def del_commentLikes(commentid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    return jsonify(LikesApi.delLikesComment(commentid, userid))
Example #17
0
def del_articleLikes(articleid):
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'login required'))
    return jsonify(LikesApi.delLikesArticle(articleid, userid))
Example #18
0
def get_userinfo():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    return jsonify(UserApi.getUserInfoByUserid(userid))
Example #19
0
def get_selfId():
    userid = IdentifyUtil.get_user_id()
    if not userid:
        return jsonify(Common.falseReturn(None, 'user not find'))
    return jsonify(Common.trueReturn(userid, 'query ok'))