示例#1
0
def get_token():
    '''获取一个口令,用于保持登陆'''
    params = request.get_json()
    return jsonify(
        IdentifyUtil.authenticate(
            params.get('username'),
            IdentifyUtil.hash_secret(params.get('password'))))
示例#2
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'))
示例#3
0
文件: views.py 项目: vaststar/Blog
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}')
        )
示例#4
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')))
示例#5
0
文件: views.py 项目: vaststar/Blog
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'))
示例#6
0
文件: views.py 项目: vaststar/Blog
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'))
示例#7
0
文件: userApi.py 项目: vaststar/Blog
 def updateUserBase(userid,username,password):
     if not blogDB.getUserById(userid):
         return Common.falseReturn(None, "{} doesn't exist in user_base".format(userid))
     if not username or not password:
         return Common.falseReturn(None, 'username or password cannot be empty')
     if blogDB.updateUser(userid,username,IdentifyUtil.hash_secret(password)):
         return Common.trueReturn({'userid':userid},'change ok')
     else:
         return Common.falseReturn(None,'change false')
示例#8
0
文件: views.py 项目: vaststar/Blog
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))
示例#9
0
文件: userApi.py 项目: vaststar/Blog
 def registerUserBase(username,password):
     if not username or not password:
         return Common.falseReturn(None, 'username or password cannot be empty')
     if blogDB.getUserByName(username) is not None:
         return Common.falseReturn(None,'{} is already exists'.format(username))
     userid = blogDB.addUser(username, IdentifyUtil.hash_secret(password))
     if userid is not None:
         return Common.trueReturn({'userid':userid},'register ok')
     else :
         return Common.falseReturn('unknown reason','register wrong')
示例#10
0
文件: views.py 项目: vaststar/Blog
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'))
示例#11
0
文件: views.py 项目: vaststar/Blog
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'))
示例#12
0
文件: views.py 项目: vaststar/Blog
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)
示例#13
0
文件: views.py 项目: vaststar/Blog
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')))
示例#14
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)
示例#15
0
文件: views.py 项目: vaststar/Blog
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))
示例#16
0
文件: views.py 项目: vaststar/Blog
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'))
示例#17
0
文件: views.py 项目: vaststar/Blog
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))
示例#18
0
文件: views.py 项目: vaststar/Blog
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))
示例#19
0
文件: views.py 项目: vaststar/Blog
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))
示例#20
0
文件: views.py 项目: vaststar/Blog
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))
示例#21
0
文件: userApi.py 项目: vaststar/Blog
 def updateUserPassword(userid,password):
     if blogDB.updateUserPassword(userid,IdentifyUtil.hash_secret(password)):
         return Common.trueReturn(userid,'change password ok')
     return Common.falseReturn(None,"change password error")
示例#22
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))
示例#23
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'))