コード例 #1
0
ファイル: views.py プロジェクト: wlf5241/alchemyCMS
def login_in():
    if request.method == 'GET':
        if session.get(FRONT_USER_ID):
            return redirect(url_for('front.index'))
        else:
            return_to = request.referrer
            if return_to and return_to!=request.url \
                    and return_to != url_for('front.signup') and safeutils.is_safe_url(return_to):
                return render_template('front/front_login.html',
                                       return_to=return_to)
            return render_template('front/front_login.html')
    else:
        form = LoginForm(request.form)
        # print(form.data)
        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[FRONT_USER_ID] = user.id
                if remember:
                    session.permanent = True
                return resful.success()
            else:
                return resful.params_error('手机号或密码错误')
        else:
            return resful.params_error(form.get_error())
コード例 #2
0
ファイル: views.py プロジェクト: wlf5241/alchemyCMS
def add_post():
    if request.method == 'GET':
        boards = BoardModel.query.all()
        cboard = request.args.get('cboard', type=int, default=None)
        return render_template('front/front_add_post.html',
                               boards=boards,
                               cboard=cboard)
    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 resful.params_error(message='没有这个版块')
            post = PostModel(title=title, content=content, board_id=board_id)
            post.board = board
            post.author = g.front_user
            db.session.add(post)
            db.session.commit()
            return resful.success('注册成功')
        else:
            return resful.params_error(message=form.get_error())
コード例 #3
0
def del_banner():
    banner_id = request.form.get("banner_id")
    if not banner_id:
        return resful.params_error("请传入bnner_id")
    banner = Banner.query.get(banner_id)
    if not banner:
        return resful.params_error("没有这个轮播图")
    db.session.delete(banner)
    db.session.commit()
    return resful.success()
コード例 #4
0
def del_boards():
    board_id = request.form.get("board_id")
    if not board_id:
        return resful.params_error("请传入board_id")
    board = BoardModel.query.get(board_id)
    if not board:
        return resful.params_error("没有这个版块")
    db.session.delete(board)
    db.session.commit()
    return resful.success()
コード例 #5
0
def uhpost():
    post_id = request.form.get('post_id')
    if not post_id:
        return resful.params_error("请传入帖子id")
    post = PostModel.query.get(post_id)
    if not post:
        return resful.params_error("没有这篇帖子")
    highlight = HighlightPostModel.query.filter_by(post_id=post_id).first()
    db.session.delete(highlight)
    db.session.commit()
    return resful.success()
コード例 #6
0
def delete_banner():
    banner_id = request.form.get('banner_id')
    print(banner_id)
    if not banner_id:
        return resful.params_error(message='请传入轮播图id')
    banner = BannerModel.query.get(banner_id)
    if not banner:
        return resful.params_error(message='没有这个轮播图')
    db.session.delete(banner)
    db.session.commit()
    return resful.success()
コード例 #7
0
def delete_boards():
    board_id = request.form.get('board_id')
    if not board_id:
        return resful.params_error(message='请传入版块ID')
    board = BoardModel.query.get(board_id)
    if board:
        db.session.delete(board)
        db.session.commit()
        return resful.success()
    else:
        return resful.params_error(message='没有这个版块')
コード例 #8
0
def hpost():
    post_id = request.form.get('post_id')
    if not post_id:
        return resful.params_error(message='请传入帖子id')
    post = PostModel.query.get(post_id)
    if not post:
        return resful.params_error(message='没有这篇帖子')
    highlight = HighLight()
    highlight.post = post
    db.session.add(highlight)
    db.session.commit()
    return resful.success()
コード例 #9
0
def hpost():
    # 获取不到id,返回,获取不到这篇帖子返回
    post_id = request.form.get('post_id')
    if not post_id:
        return resful.params_error("请传入帖子id")
    post = PostModel.query.get(post_id)
    if not post:
        return resful.params_error("没有这篇帖子")
    hightpost = HighlightPostModel()
    hightpost.post = post
    db.session.add(hightpost)
    db.session.commit()
    return resful.success()
コード例 #10
0
def uhpost():
    post_id = request.form.get('post_id')
    if not post_id:
        return resful.params_error(message='请传入帖子id')
    post = PostModel.query.get(post_id)
    if not post:
        return resful.params_error(message='没有这篇帖子')
    # print(post_id,'ddd')
    highlight = HighLight.query.filter_by(post_id=post_id).first()
    # print(highlight)
    db.session.delete(highlight)
    db.session.commit()
    return resful.success()
コード例 #11
0
def uboards():
    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 resful.success()
        else:
            return resful.params_error(message="没有这个板块")
    return resful.params_error(form.get_error())
コード例 #12
0
 def post(self):
     form = ResetPwdForm(request.form)
     if form.validate():
         oldpwd = form.old_pwd.data
         newpwd = form.new_pwd.data
         user = g.cms_user
         if user.check_pwd(oldpwd):
             user.password = newpwd
             db.session.commit()
             ###{"code":200,message:"修改成功",}
             return resful.success(message="密码修改成功")
         else:
             return resful.params_error("旧密码错误")
     # 给android,ios写后台用restful更合适
     else:
         return resful.params_error(form.get_error())
コード例 #13
0
    def post(self):
        form = ResetpwdForm(request.form)
        print(form.data)
        if form.validate():
            oldpassword = form.oldpwd.data
            newpassword = form.newpwd.data

            user = g.cms_user
            if user.check_password(oldpassword):
                user.password = newpassword
                db.session.commit()
                return resful.success('密码修改成功')
            else:
                return resful.params_error('旧密码输入错误')
        else:
            message = form.get_error()
            return resful.params_error(message)
コード例 #14
0
def add_comment():
    form = AddCommentForm(request.form)
    if form.validate():
        conment = form.content.data
        post_id = form.post_id.data
        post = PostModel.query.get(post_id)
        if post:
            comment = CommentModel(content=conment)
            comment.post = post
            comment.author = g.front_user
            db.session.add(comment)
            db.session.commit()
            return resful.success()
        else:
            return resful.params_error()
    else:
        return resful.params_error(form.get_error())
コード例 #15
0
 def post(self):
     # 获取邮箱和验证码
     form = ResetEmailForm(request.form)
     if form.validate():
         email = form.email.data
         g.cms_user.email == email
         db.session.commit()
         return resful.success("修改成功")
     else:
         return resful.params_error(form.get_error())
コード例 #16
0
def add_boards():
    form = AddBoardsForm(request.form)
    if form.validate():
        name = form.name.data
        board = BoardModel(name=name)
        db.session.add(board)
        db.session.commit()
        return resful.success()
    else:
        return resful.params_error(message=form.get_error())
コード例 #17
0
def edit_banners():
    form = EditbannerForm(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
        weight_url = form.weight_url.data
        banner = Banner.query.get(banner_id)
        if banner:
            banner.name = name
            banner.image_url = image_url
            banner.link_url = link_url
            banner.weight_url = weight_url
            db.session.commit()
            return resful.success()
        else:
            return resful.params_error("没有这个轮播图")
    else:
        return resful.params_error(message=form.get_error())
コード例 #18
0
def email_captcha():
    # /email_captcha/?email=xx.com
    email = request.args.get('email')
    if not email:
        return resful.params_error("请传递邮箱参数")
    source = list(string.ascii_letters)  # ['a','b'..z ..Z]
    source.extend(map(lambda x: str(x), range(0, 10)))
    # source.extend(["0","1","2","3","4","5","6","7","8","9"])
    # 随机采用
    yanzhengma = "".join(random.sample(source, 6))
    message = Message("趣论坛验证码", recipients=[email])
    message.body = '您的验证码是 %s,请复制验证码到网址进行邮箱修改' % yanzhengma
    message.html = '<h3>您的验证码是 %s,请复制验证码到网址进行邮箱修改</h3>' % yanzhengma
    try:
        mail.send(message=message)
    except:
        return resful.params_error("发送验证码异常")
    ##把邮箱,验证码绑定在一起,60s缓存
    zlcache.set(email, yanzhengma)
    return resful.success("发送成功")
コード例 #19
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 resful.params_error("没有这个版块")
            post = PostModel(title=title, content=content)
            post.board = board
            post.author_id = g.front_user.id
            db.session.add(post)
            db.session.commit()
            return resful.success()
        else:
            return resful.params_error(form.get_error())
コード例 #20
0
def update_banners():
    form = UpdateBannerForm(request.form)
    print(form.data, 'llal')
    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_or_404(banner_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 resful.success()
        else:
            return resful.params_error(message='没有这个轮播图')
    else:
        return resful.params_error(message=form.get_error())
コード例 #21
0
 def post(self):
     reset_email_form = RestEmailForm(request.form)
     if reset_email_form.validate():
         email = reset_email_form.email.data
         g.cms_user.email = email
         db.session.commit()
         return resful.success('修改成功')
     elif reset_email_form.errors:
         print(reset_email_form.errors)
         errors = reset_email_form.get_error()
         return resful.params_error(errors)
     else:
         return resful.server_error()
コード例 #22
0
def banners():
    addBanner = AddbannerForm(request.form)
    if addBanner.validate():
        name = addBanner.name.data
        imge_url = addBanner.image_url.data
        link_url = addBanner.link_url.data
        weight_url = addBanner.weight_url.data
        banner = Banner(name=name,
                        image_url=imge_url,
                        link_url=link_url,
                        weight_url=weight_url)
        db.session.add(banner)
        db.session.commit()
        return resful.success()
    else:
        return resful.params_error()
コード例 #23
0
ファイル: views.py プロジェクト: wlf5241/alchemyCMS
 def post(self):
     form = SignUpForm(request.form)
     print(form.data)
     if form.validate():
         telephone = form.telephone.data
         username = form.username.data
         password = form.password1.data
         user = FrontUser(telephone=telephone,
                          password=password,
                          username=username)
         db.session.add(user)
         db.session.commit()
         return resful.success()
     else:
         print(form.errors)
         return resful.params_error(form.get_error())
コード例 #24
0
ファイル: views.py プロジェクト: wlf5241/alchemyCMS
def i_forget():
    if request.method == 'GET':
        return render_template('front/front_iforget.html')
    else:
        form = IForgetForm(request.form)
        if form.validate():
            user = FrontUser.query.filter_by(
                telephone=form.telephone.data).first()
            print(user)
            user.password = form.password1.data
            db.session.add(user)
            db.session.commit()
            session.clear()
            return resful.success('密码修改成功')
        else:
            print(form.errors)
            return resful.params_error(form.get_error())
コード例 #25
0
def add_banners():
    form = AddBannerForm(request.form)
    if form.validate():
        # name1=request.form.get('name')
        name = form.name.data
        # print(name1,name,'美丽的世界')
        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 resful.success()
    else:
        print(form.errors)
        return resful.params_error(form.get_error())
コード例 #26
0
def email_captcha():
    email = request.args.get('email')
    if not email:
        return resful.params_error('请输入你的邮箱')
    source = list(string.ascii_letters)
    source.extend(map(lambda x: str(x), range(0, 10)))
    #还有一种写法,但是太low了
    # source.extend(['0','1','2','3','4','5','6','7','8','9','10'])
    random_code_captcha = random.sample(source, 6)
    captcha = ''.join(random_code_captcha)
    message = Message('论坛邮箱验证码', recipients=[email], body='您的验证码是%s' % captcha)
    try:
        mail.send(message)
    except:
        return resful.server_error()

    landicache.set(email, captcha)

    return resful.success('邮件已发送')
コード例 #27
0
ファイル: views.py プロジェクト: wlf5241/alchemyCMS
def sms_captcha():
    form = SmsCaptchaForm(request.form)
    if form.validate():
        telephone = form.telephone.data
        captcha = get_back_random_cptcha()
        print('电话号码是', telephone)
        print('发送给用户的短信验证码是', captcha)
        #在memcache里存telephone和验证码
        landicache.set(telephone, captcha.lower())
        # message='【雨晨论坛】您的验证码是{}。如非本人操作,请忽略本短信'.format(captcha)
        # clnt = YunpianClient(DevConfig.YUNPIAN_CODE)
        # param = {YC.MOBILE: telephone, YC.TEXT: message}
        # if clnt.sms().single_send(param):
        #     #在memcache里存telephone和验证码
        #     landicache.set(telephone,captcha.lower())
        #     return resful.success('短信验证码发送成功')
        # else:
        #     return resful.params_error(message='请传入手机号码')
        return resful.success('短K信验证码发送成功')
    else:
        return resful.params_error(message='参数错误')