Beispiel #1
0
def dbanner():
    banner_id = request.form.get('banner_id')
    if not banner_id:
        return restful.param_error(message="请输入轮播图ID")
    banner = Banner.query.get(banner_id)
    if not banner:
        return restful.param_error(message="没有这个轮播图")
    db.session.delete(banner)
    db.session.commit()
    return restful.success()
Beispiel #2
0
def dboard():
    board_id = request.form.get('board_id')
    if not board_id:
        return restful.param_error(message="请输入板块ID")
    board = Board.query.get(board_id)
    if not board:
        return restful.param_error(message="没有这个板块")
    db.session.delete(board)
    db.session.commit()
    return restful.success()
Beispiel #3
0
def dcomment():
    comment_id = request.form.get('comment_id')
    if not comment_id:
        return restful.param_error(message="请输入评论ID")
    comment = Comment.query.get(comment_id)
    if not comment:
        return restful.param_error(message="没有这条评论")
    db.session.delete(comment)
    db.session.commit()
    return restful.success()
Beispiel #4
0
def dpost():
    post_id = request.form.get('post_id')
    if not post_id:
        return restful.param_error(message="请输入帖子ID")
    post = Post.query.get(post_id)
    if not post:
        return restful.param_error(message="没有这篇帖子")
    [db.session.delete(comment) for comment in post.comments]
    db.session.delete(post)
    db.session.commit()
    return restful.success()
Beispiel #5
0
def dboard():
    board_id = request.form.get('board_id')
    if not board_id:
        return restful.param_error('该板块不存在')

    board = BoardModel.query.get(board_id)
    if not board:
        return restful.param_error('该板块不存在')
    db.session.delete(board)
    db.session.commit()
    return restful.success()
Beispiel #6
0
def del_post():
    post_id = request.form.get('post_id')
    if not post_id:
        return restful.param_error(message='Please input post id')

    post = Post.query.get(post_id)
    if not post:
        return restful.param_error(message='This post is not exist')

    db.session.delete(post)
    db.session.commit()
    return restful.success()
Beispiel #7
0
def del_board():
    board_id = request.form.get('board_id')
    if not board_id:
        return restful.param_error(message='Please input board id')

    board = Board.query.get(board_id)
    if board:
        db.session.delete(board)
        db.session.commit()
        return restful.success()
    else:
        return restful.param_error(message='There is no this board')
Beispiel #8
0
def del_banner():
    banner_id = request.form.get('banner_id')
    if not banner_id:
        return restful.param_error(message='banner id missing')

    banner = BannerModel.query.get(banner_id)

    if banner:
        db.session.delete(banner)
        db.session.commit()
        return restful.success()
    else:
        return restful.param_error(message='There is no this banner')
Beispiel #9
0
def edit_board():
    form = EditBoardForm(request.form)
    if form.validate():
        board_id = form.board_id.data
        board = Board.query.get(board_id)
        if board:
            board.board_name = form.board_name.data
            db.session.commit()
            return restful.success()
        else:
            return restful.param_error(form.get_error(message='There is no this board'))
    else:
        return restful.param_error(form.get_error())
Beispiel #10
0
def dbanner():
    # post方式
    banner_id = request.form.get('banner_id')
    if not banner_id:
        return restful.param_error('该轮播图已经删除,请重新刷新页面')

    banner = BannerModel.query.get(banner_id)
    if banner:
        banner.is_delete = 0
        # db.session.delete(banner)
        db.session.commit()
        return restful.success(data={'delete': 0})
    else:
        return restful.param_error(message='轮播图不存在')
Beispiel #11
0
def uboard():
    form = UpdateBoardForm(request.form)
    if form.validate():
        name = form.name.data
        board_id = form.board_id.data
        board = Board.query.get(board_id)
        if board:
            board.name = name
            db.session.commit()
            return restful.success()
        else:
            return restful.param_error(message="没有这个板块")
    else:
        restful.param_error(form.get_error())
Beispiel #12
0
def highlight_post():
    post_id = request.form.get("post_id")
    if not post_id:
        return restful.param_error(message='Please input post id')

    post = Post.query.get(post_id)
    if not post:
        return restful.param_error(message='This post i not exist')

    highlight = HighLightPost()
    highlight.post = post
    db.session.add(highlight)
    db.session.commit()
    return restful.success()
Beispiel #13
0
def del_highlight_post():
    post_id = request.form.get("post_id")
    if not post_id:
        return restful.param_error(message='Please input post id')

    post = Post.query.get(post_id)
    if not post:
        return restful.param_error(message='This post i not exist')

    #highlight = post.highlight   <class 'sqlalchemy.orm.collections.InstrumentedList'>
    highlight = post.highlight[0]
    print(highlight)
    db.session.delete(highlight)
    db.session.commit()
    return restful.success()
Beispiel #14
0
def add_comment():
    form = AddCommentForm(request.form)
    if form.validate():
        content = form.content.data
        post_id = form.post_id.data
        post = Post.query.get(post_id)
        if not post:
            return restful.param_error(message='This post is not exist')
        author = g.user
        comment = Comment(content=content, post=post, author=author)
        db.session.add(comment)
        db.session.commit()
        return restful.success()
    else:
        return restful.param_error(form.get_error())
Beispiel #15
0
def sms_captcha():
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        # result = alidayuSMS.sendSMS(telephone, code=captcha)
        result = send_sms_captcha.delay(telephone=telephone, code=captcha)
        if result:
            print("短信验证码:" + captcha)
            rmcache.set(telephone, captcha, timeout=600)  #手机号作为key
            return restful.success()
        else:
            return restful.param_error(message="验证码发送失败!")
    else:
        return restful.param_error(message=form.get_error())
Beispiel #16
0
def course_token(request):
    """
    生成前端视频播放所需要的token
    :param request:
    :return: token
    """
    file = request.GET.get('video') # 这里的file是一个完整的视频链接地址
    course_id = request.GET.get('course_id')
    exists = CourseOrder.objects.filter(course_id=course_id, buyer=request.user, status=2).exists()  # 处理用户是否购买课程的逻辑
    if not exists:
        return restful.param_error(message='请先购买该课程!')

    expired_time = int(time.time()) + 2 * 60 * 60
    USER_ID = settings.BAIDU_CLOUD_USER_ID
    USER_KEY = settings.BAIDU_CLOUD_USER_KEY

    # 获取的file的地址url如下
    # file=http://hemvpc6ui1kef2g0dd2.exp.bcevod.com/mda-igjsr8g7z7zqwnav/mda-igjsr8g7z7zqwnav.m3u8
    # 1.获取地址url中的文件名的扩展名
    # 2.去除扩展名,获取文件名
    extension = os.path.splitext(file)[1] # 将文件名和扩展名分离: (filename, extension)
    media_id = file.split('/')[-1].replace(extension, '') # 获取二进制文件名: mda-igjsr8g7z7zqwnav

    # 将user_key编码成utf8格式
    key = USER_KEY.encode('utf-8')
    message = '/{0}/{1}'.format(media_id, expired_time).encode('utf-8')

    # 数字签名
    signature = hmac.new(key, message, digestmod=hashlib.sha256).hexdigest()
    token = '{0}_{1}_{2}'.format(signature, USER_ID, expired_time)

    return restful.result(data={'token': token})
Beispiel #17
0
    def post(self, request):
        forms = EditCourseForm(request.POST)
        if forms.is_valid():
            title = forms.cleaned_data.get('title')
            category_id = forms.cleaned_data.get('category_id')
            teacher_id = forms.cleaned_data.get('teacher_id')
            video_url = forms.cleaned_data.get('video_url')
            cover_url = forms.cleaned_data.get('cover_url')
            price = forms.cleaned_data.get('price')
            duration = forms.cleaned_data.get('duration')
            profile = forms.cleaned_data.get('profile')

            teacher = Teacher.objects.get(pk=teacher_id)
            category = CourseCategory.objects.get(pk=category_id)

            pk = forms.cleaned_data.get('pk')

            Course.objects.filter(pk=pk).update(title=title,
                                                category=category,
                                                teacher=teacher,
                                                video_url=video_url,
                                                cover_url=cover_url,
                                                price=price,
                                                duration=duration,
                                                profile=profile)

            return restful.ok(message='课程编辑成功!')
        else:
            return restful.param_error(message="表单验证失败!")
Beispiel #18
0
def acomment():
    form = AddCommentForm(request.form)
    if form.validate():
        content = form.content.data
        post_id = form.post_id.data
        post = Post.query.get(post_id)
        if post:
            comment = Comment(content=content)
            comment.post = post
            comment.user = g.front_user
            db.session.add(comment)
            db.session.commit()
            return restful.success()
        else:
            return restful.param_error(message=form.get_error('没有这篇帖子'))
    else:
        return restful.param_error(message=form.get_error())
Beispiel #19
0
 def post(self):
     resetpwd_form = ResetPwdForm(request.form)
     if resetpwd_form.validate():
         oldpwd = resetpwd_form.oldpwd.data
         newpwd = resetpwd_form.newpwd.data
         user = g.cms_user
         if user.check_password(oldpwd):
             user.password = newpwd
             db.session.commit()
             return restful.success(message='密码修改成功')
         else:
             return restful.param_error(message='旧密码错误')
     else:
         # 没认证通过(即密码长度不通过,或者两次密码输入不一致)
         # message = resetpwd_form.errors
         print(resetpwd_form.get_error())
         return restful.param_error(message=resetpwd_form.get_error())
Beispiel #20
0
def uboard():
    form = UpdateBoardForm(request.form)
    if form.validate():
        board_id = form.board_id.data
        # print(board_id)
        name = form.name.data
        # print(name)
        board = BoardModel.query.filter_by(id=board_id).first()
        if board:
            # print(board)
            board.name = name
            db.session.commit()
            return restful.success()
        else:
            return restful.param_error(message='这个板块不存在')
    else:
        return restful.param_error(form.get_error())
Beispiel #21
0
 def post(self):
     form = SignInForm(request.form)
     if form.validate_on_submit():
         telephone = form.telephone.data
         password = form.password.data
         remember = form.remember.data
         user = FrontUser.query.filter_by(telephone=telephone).first()
         if user and user.check_password(password):
             session[constants.USER_ID] = user.id
             print('view user id {}'.format(user.id))
             if remember:
                 session.permanent = True
             return restful.success()
         else:
             return restful.param_error(
                 message='telephone or password error')
     else:
         return restful.param_error(message=form.get_error())
Beispiel #22
0
 def post(self):
     form = ResetEmailForm(request.form)
     if form.validate():
         email = form.email.data
         g.administrator.email = email
         db.session.commit()
         return restful.success()
     else:
         return restful.param_error(message=form.get_error())
Beispiel #23
0
 def post(self):
     form = VerifyEmailForm(request.form)
     if form.validate():
         email = form.email.data
         g.cms_user.email = email
         db.session.commit()
         return restful.success()
     else:
         return restful.param_error("验证失败")
Beispiel #24
0
 def post(self):
     form = ResetEmailForm(request.form)
     if form.validate():
         newemail = form.newemail.data
         g.cms_user.email = newemail
         db.session.commit()
         return restful.success()
     else:
         return restful.param_error(form.get_error())
Beispiel #25
0
 def post(self):
     form = ResetPwdForm(request.form)
     if form.validate():
         oldpwd = form.oldpwd.data
         newpwd = form.newpwd.data
         user = g.cms_user
         if user.check_password(oldpwd):
             user.password = newpwd
             db.session.commit()
             # return jsonify({"code":200, "message":""})
             return restful.success()
         else:
             # return jsonify({"code":400, "message":"原密码错误"})
             return restful.param_error("原密码错误")
     else:
         message = form.get_error()
         # return jsonify({"code":400, "message":message})
         return restful.param_error(message)
Beispiel #26
0
def chpost():
    post_id = request.form.get('post_id')
    post = PostModel.query.get(post_id)
    if not post:
        return restful.param_error('该帖子不存在')
    highlight_post = HighLightPostModel.query.filter_by(post=post).first()
    db.session.delete(highlight_post)
    db.session.commit()
    return restful.success()
Beispiel #27
0
 def post(self):
     form = AddPostForm(request.form)
     if form.validate():
         title = form.title.data
         content = form.content.data
         board_id = form.board_id.data
         board = Board.query.get(board_id)
         if board:
             post = Post(title=title, content=content)
             post.board = board
             post.author = g.front_user
             db.session.add(post)
             db.session.commit()
             return restful.success()
         else:
             return restful.param_error(message="板块不存在!")
     else:
         return restful.param_error(message=form.get_error())
Beispiel #28
0
def add_board():
    form = AddBoardForm(request.form)
    if form.validate():
        board_name = form.board_name.data
        board = Board(board_name=board_name)
        db.session.add(board)
        db.session.commit()
        return restful.success()
    else:
        return restful.param_error(form.get_error())
Beispiel #29
0
def aboard():
    form = AddBoardForm(request.form)
    if form.validate():
        name = form.name.data
        board = BoardModel(name=name)
        db.session.add(board)
        db.session.commit()
        return restful.success()
    else:
        return (restful.param_error(message=form.get_error()))
Beispiel #30
0
def edit_banner():
    form = EditBannerForm(request.form)
    if form.validate():
        id = form.banner_id.data
        name = form.name.data
        image_url = form.image_url.data
        link_url = form.link_url.data
        priority = form.priority.data
        banner = BannerModel.query.get(id)
        if banner:
            banner.name = name
            banner.image_url = image_url
            banner.link_url = link_url
            banner.priority = priority
            db.session.add(banner)
            db.session.commit()
            return restful.success()
        return restful.param_error(message='There is no this banner')
    else:
        return restful.param_error(form.get_error())