Exemple #1
0
def dbanenr():
    banner_id = request.form.get('banner_id')
    if not banner_id:
        return restful.paramError(message='请输入轮播图ID')
    banner = BannerModel.query.get(banner_id)
    if not banner:
        return restful.paramError(message='没有该图片!')
    db.session.delete(banner)
    db.session.commit()
    return restful.success()
Exemple #2
0
def dboard():
    board_id = request.form.get('board_id')
    if not board_id:
        return restful.paramError('请输入板块ID!')
    board = BoardModel.query.get(board_id)
    if not board:
        return restful.paramError(message='该板块不存在!')
    db.session.delete(board)
    db.session.commit()
    return restful.success()
Exemple #3
0
def uhpost():
    post_id = request.form.get("post_id")
    if not post_id:
        return restful.paramError('请输入帖子ID')
    post = PostModel.query.get(post_id)
    if not post:
        return restful.paramError('该帖子不存在!')
    highlight = HighlightPostModel.query.filter_by(post_id=post_id).first()
    db.session.delete(highlight)
    db.session.commit()
    return restful.success()
Exemple #4
0
def hpost():
    post_id = request.form.get("post_id")
    if not post_id:
        return restful.paramError('请输入帖子ID')
    post = PostModel.query.get(post_id)
    if not post:
        return restful.paramError('该帖子不存在!')
    highlight = HighlightPostModel()
    highlight.post = post
    db.session.add(highlight)
    db.session.commit()
    return restful.success()
Exemple #5
0
def uboard():
    form = UpdateBoardForm(request.form)
    if form.validate():
        board_id = form.board_id.data
        name = form.name.data
        board = BoardModel.query.get(board_id)
        if board:
            board.name = name
            db.session.commit()
            return restful.success()
        return restful.paramError(message='该板块不存在!')

    return restful.paramError(message=form.get_error())
Exemple #6
0
def add_comment():
    form = AddCommentForm(request.form)
    if form.validate():
        content = form.content.data
        post_id = form.post_id.data
        post = PostModel.query.get(post_id)
        if post:
            comment = CommentModel(content=content)
            comment.post = post
            comment.author = g.front_user
            db.session.add(comment)
            db.session.commit()
            return restful.success()
        return restful.paramError('该帖子不存在!')
    return restful.paramError(form.get_error())
Exemple #7
0
 def post(self):
     form = SigninForm(request.form)
     if form.validate():
         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[config.FRONT_USER_ID] = user.id
             if remember:
                 session.permanent = True
             return restful.success()
         else:
             return restful.paramError(message='手机号码或密码错误!')
     else:
         return restful.paramError(message=form.get_error())
Exemple #8
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 restful.paramError("旧密码错误")
     else:
         # message = form.get_error()
         # return jsonify({"code":400, "message":message})
         return restful.paramError(form.get_error())
Exemple #9
0
 def post(self):
     form = ResetEmailForm(request.form)
     if form.validate():
         email = form.email.data
         g.cms_user.email = email
         db.session.commit()
         return restful.success()
     else:
         return restful.paramError(form.get_error())
Exemple #10
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()
    return restful.paramError(message=form.get_error())
Exemple #11
0
def sms_captchas():
    telephone = request.args.get("telephone")
    if not telephone:
        return restful.paramError(message="手机号不能为空")

    code = aliyunAPI.get_code(1)
    print("验证码:",code)
    res = aliyunAPI.send_sms(telephone=telephone,code=code)
    zlcache.set(telephone, code)
    return res
Exemple #12
0
def ubanner():
    form = UpdateBannerForm(request.form)
    if form.validate():
        banner_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(banner_id)
        if banner:
            banner.name = name
            banner.image_url = image_url
            banner.link_url = link_url
            banner.priority = priority
            db.session.commit()
            return restful.success()
        else:
            return restful.paramError(message='没有该图片!')

    return restful.paramError(message=form.get_error())
Exemple #13
0
def apost():
    if request.method == 'GET':
        boards = BoardModel.query.all()
        return render_template('front/front_apost.html', boards=boards)

    else:
        form = AddPostForm(request.form)
        if form.validate():
            title = form.title.data
            content = form.content.data
            board_id = form.board_id.data
            board = BoardModel.query.get(board_id)
            if not board:
                return restful.paramError(message='没有该板块!')
            post = PostModel(title=title, content=content)
            post.board = board
            post.author = g.front_user
            db.session.add(post)
            db.session.commit()
            return restful.success()
        return restful.paramError(message=form.get_error())
Exemple #14
0
 def post(self):
     form = SignupForm(request.form)
     if form.validate():
         telephone = form.telephone.data
         username = form.username.data
         password = form.password1.data
         user = FrontUser(telephone=telephone,
                          username=username,
                          password=password)
         db.session.add(user)
         db.session.commit()
         return restful.success()
     else:
         print("front/views/post", form.get_error())
         return restful.paramError(message=form.get_error())
Exemple #15
0
def abanner():
    form = AddBannerForm(request.form)
    if form.validate():
        name = form.name.data
        image_url = form.image_url.data
        link_url = form.link_url.data
        priority = form.priority.data
        banner = BannerModel(name=name,
                             image_url=image_url,
                             link_url=link_url,
                             priority=priority)
        db.session.add(banner)
        db.session.commit()
        return restful.success()
    return restful.paramError(message=form.get_error())
Exemple #16
0
def sms_captcha():
    req = json.loads(request.get_data(as_text=True))
    #print(req["telephone"])
    #print(type(req))
    print(req)
    #form  = SMSCaptchaForm(req)
    #for key,value in data.items():
    telephone = req["telephone"]

    if telephone:
        #form.validate()
        #telephone = form.telephone.data
        code = aliyunAPI.get_code(1)
        zlcache.set(telephone, code)
        res = aliyunAPI.send_sms(telephone, code)
        print(code)
        return res
    else:
        return restful.paramError(message="参数错误")
Exemple #17
0
def sms_captcha():
    # telephone , timeStamp
    # md5(timeStamp + telephone + salt)
    form = SMSCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = Captcha.gene_text(number=4)
        zlcache.set(telephone, captcha.lower())
        send_sms_captcha(telephone, captcha)
        return restful.success()
        # print(f"短信验证码: {captcha}", type(captcha))
        # if juheshuju.send(telephone, captcha=captcha):
        #     zlcache.set(telephone, captcha.lower())
        #     print(f"发送成功, 短信验证码: {captcha}", type(captcha))
        #     return restful.success()
        # else:
        #     # print(f"发送失败, 短信验证码: {captcha}", type(captcha))
        #     return restful.paramError('发送失败,请稍后再试!')
    return restful.paramError(message='参数错误!')
Exemple #18
0
def email_captcha():
    # /email_captcha/[email protected]
    email = request.args.get('email')
    if not email:
        return restful.paramError('请输入邮箱参数')
    # 发邮件
    source = list(string.ascii_letters)
    source.extend(list(map(str, range(0, 10))))
    captcha = "".join(random.sample(source, 6))
    # message = Message('BBS邮箱验证码', recipients=[email], body=f"您的验证码是: {captcha}\n【10分钟之内有效】" )
    # try:
    #     mail.send(message)
    # except:
    #     return restful.serverError()

    send_mail.delay('LGF_BBS邮箱验证码', [email], f"您的验证码是: {captcha}\n【10分钟之内有效】")
    zlcache.set(email, captcha)

    return restful.success()