コード例 #1
0
def add_post():
    if flask.request.method == 'GET':
        boards = public_models.BoardModel.query.filter_by(is_live=True).all()
        return flask.render_template('front/add_post.html', boards=boards)
    else:
        form = Front_add_post_form(flask.request.form)
        if form.validate():
            title = form.title.data
            post = public_models.Post.query.filter_by(title=title,
                                                      is_live=True).first()
            if post:
                return xt_json.json_params_error('对不起 该帖子标题已存在!')
            board_id = form.board_id.data
            content = form.content.data
            board = public_models.BoardModel.query.get(board_id)
            front_user = flask.g.front_user
            post = public_models.Post(title=title,
                                      content=content,
                                      create_time=datetime.datetime.now())
            board.posts.append(post)
            front_user.posts.append(post)
            # 获取当前发帖的日期
            post_date = datetime.date.today()
            post_date = str(post_date) + 'post'
            if not LOGIN_TEMP.has_key(post_date):
                LOGIN_TEMP[post_date] = 1
                front_user.bbs_points += 5  # 帖子发表一次用户积分加5
            elif LOGIN_TEMP[post_date] <= 5:
                front_user.bbs_points += 5  # 帖子发表一次用户积分加5
                LOGIN_TEMP[post_date] += 1
            db.session.commit()
            return xt_json.json_result_ok('恭喜 帖子发表成功!')
        else:
            return xt_json.json_params_error(form.get_error())
コード例 #2
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def add_manager():
    if flask.request.method == 'GET':
        cms_roles = CMSRole.query.all()
        return flask.render_template('cms/add_manager.html',cms_roles=cms_roles)
    else:
        form = Add_manager_form(flask.request.form)
        if form.validate():
            username = form.username.data
            password = form.password.data
            email = form.email.data
            web_check = flask.request.form.getlist('web_check[]')
            cms_user = CMSUser.query.filter_by(username=username).first()
            if cms_user:
                return xt_json.json_params_error('对不起 该用户名已存在!')
            cms_user = CMSUser.query.filter_by(email=email).first()
            if cms_user:
                return xt_json.json_params_error('对不起 该邮箱已存在!')
            cms_user = CMSUser(username=username,password=password,email=email)
            if web_check:
                cms_roles = []
                for check in web_check:
                    cms_role = CMSRole.query.get(check)
                    cms_roles.append(cms_role)
                cms_user.cms_roles = cms_roles
                db.session.add(cms_user)
                db.session.commit()
            else:
                return xt_json.json_params_error('对不起 必须指定所属分组!')
            return xt_json.json_result_ok('恭喜 添加CMS用户成功!')
        else:
            return xt_json.json_params_error(form.get_error())
コード例 #3
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def resetpwd():
    if flask.request.method == 'GET':
        return flask.render_template('cms/resetpwd.html',message='')
    else:
        form = Set_pwd_form(flask.request.form)
        if form.validate():
            oldpwd = form.oldpwd.data
            newpwd = form.newpwd.data
            if flask.g.cms_user.check_pwd(oldpwd):
                flask.g.cms_user.password = newpwd
                db.session.commit()
                return xt_json.json_result_ok(message='success')
            else:
                return xt_json.json_params_error(message=u'原始密码不正确!')
        else:
            return xt_json.json_params_error(form.get_error())
コード例 #4
0
def add_second_comment_func():
    form = Front_second_comment_form(flask.request.form)
    if form.validate():
        post_id = form.id.data
        content = form.content.data
        comment_id = form.comment_id.data
        post = public_models.Post.query.filter_by(is_live=True,
                                                  id=post_id).first()
        comment = public_models.Comment.query.filter_by(is_live=True,
                                                        id=comment_id).first()
        child_comment = public_models.Comment(
            comtent=content, create_time=datetime.datetime.now())
        child_comment.origin_comment = comment
        child_comment.post = post
        child_comment.front_user = flask.g.front_user
        comment_date = datetime.date.today()
        comment_date = str(comment_date) + 'comment'
        if not LOGIN_TEMP.has_key(comment_date):
            LOGIN_TEMP[comment_date] = 1
            flask.g.front_user.bbs_points += 3  # 发表二级评论积分加3
        elif LOGIN_TEMP[comment_date] <= 8:
            flask.g.front_user.bbs_points += 3  # 发表二级评论积分加3
            LOGIN_TEMP[comment_date] += 1
        db.session.add(child_comment)
        db.session.commit()
        return xt_json.json_result_ok('评论成功!')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #5
0
def tel():
    form = front_forms.Front_check_telephone(flask.request.form)
    if form.validate():
        try:
            tel = form.telephone.data
            front_user = front_models.FrontUser.query.filter_by(
                telephone=tel).first()
            if front_user:
                return xt_json.json_params_error('对不起 该号码已存在!')
            if get_tel_captcha(tel):
                return xt_json.json_result_ok('发送验证码成功!')
            else:
                return xt_json.json_params_error('服务器忙,请稍后注册!')
        except:
            return xt_json.json_params_error('内部错误!')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #6
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def resetemail():
    if flask.request.method == 'GET':
        return flask.render_template('cms/resetemail.html')
    else:
        form = Set_email_form(flask.request.form)
        if form.validate():
            newemail = form.newemail.data
            captcha = form.captcha.data
            server_captcha = xt_cache.get(newemail)
            if server_captcha and xt_cache.check_captcha(newemail,captcha):
                flask.g.cms_user.email = newemail
                db.session.commit()
                return xt_json.json_result_ok('恭喜,修改成功!')
            else:
                return xt_json.json_params_error('对不起,验证码不正确!')
        else:
            return xt_json.json_params_error(form.get_error())
コード例 #7
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def add_board():
    name = flask.request.form.get('name')
    board = BoardModel.query.filter_by(name=name,is_live=True).first()
    if board:
        return xt_json.json_params_error('对不起 该模块已存在!')
    board = BoardModel(name=name)
    flask.g.cms_user.boards.append(board)
    db.session.commit()
    return xt_json.json_result_ok('恭喜,添加成功!')
コード例 #8
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def edit_board():
    id = flask.request.form.get('id')
    name = flask.request.form.get('name')
    board = BoardModel.query.filter_by(name=name,is_live=True).first()
    if board:
        return xt_json.json_params_error('对不起 该模块已存在!')
    board = BoardModel.query.get(id)
    board.name = name
    db.session.commit()
    return xt_json.json_result_ok('修改成功!')
コード例 #9
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def send_email_captcha():
    form = check_email_form(flask.request.form)
    if flask.request.is_xhr and form.validate():
        newemail = form.newemail.data
        email = flask.session.get(USER_SESSION_ID)
        if newemail == email:
            return xt_json.json_params_error('新邮箱和原始邮箱一致!')
        if xt_cache.get(newemail):
            return xt_json.json_params_error('已经发送验证码,3分钟内不能重复提交!')
        user = CMSUser.query.filter_by(email=newemail).first()
        if user:
            return xt_json.json_params_error('对不起该邮箱已存在!')
        captcha = xt_cache.set_captcha(6,newemail,3*60)
        if captcha:
            send_mail('个人论坛-邮箱验证码',newemail,body='您正在修改您的个人论坛CMS用户的邮箱,您的验证码是:'+captcha)
            return xt_json.json_result_ok('发送验证码成功!')
        else:
            return xt_json.json_server_error('服务器错误!')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #10
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def add_group():
    if flask.request.method == 'GET':
        return flask.render_template('cms/add_group.html')
    else:
        form = Add_group_form(flask.request.form)
        if form.validate():
            name = form.name.data
            desc = form.desc.data
            all_count = CMSRole.query.count()
            power = pow(2,all_count-1)
            if power>255:
                return xt_json.json_server_error('对不起 内部错误!')
            cms_role = CMSRole.query.filter_by(name=name).first()
            if cms_role:
                return xt_json.json_params_error('对不起,该组名已存在!')
            new_cms_role = CMSRole(name=name,desc=desc,power=power)
            db.session.add(new_cms_role)
            db.session.commit()
            return xt_json.json_result_ok('恭喜,添加该管理组成功!')
        else:
            return xt_json.json_params_error(form.get_error())
コード例 #11
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def cms_post_operate():
    if flask.request.method == 'GET':
        post_id = flask.request.args.get('id')
        if not post_id:
            return xt_json.json_params_error('数据错误!')
        post = Post.query.get(post_id)
        post.is_live = False
        db.session.commit()
        return xt_json.json_result_ok('移除成功!')
    else:
        post_id = flask.request.form.get('id')
        if not post_id:
            return xt_json.json_params_error('数据错误!')
        post = Post.query.get(post_id)
        if post.pick:
            db.session.delete(post.pick)
            db.session.commit()
            return xt_json.json_result_ok('取消加精成功!')
        else:
            pick = Pick()
            post.pick = pick
            db.session.commit()
            return xt_json.json_result_ok('加精成功!')
コード例 #12
0
def laud():
    form = Front_laud_form(flask.request.form)
    if not hasattr(flask.g, 'front_user'):
        return xt_json.json_params_error('请登录!')
    if form.validate():
        post_id = form.post_id.data
        post = public_models.Post.query.get(post_id)
        front_user = flask.g.front_user
        same_laud = public_models.Laud.query.filter_by(
            post_id=post_id, front_user_id=front_user.id).first()
        if same_laud:
            db.session.delete(same_laud)
            db.session.commit()
            return xt_json.json_result_ok('success')
        else:
            laud = public_models.Laud(create_time=datetime.datetime.now())
            laud.post = post
            laud.front_user = front_user
            db.session.add(laud)
            db.session.commit()
            return xt_json.json_result_ok('success')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #13
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def comment_manage_opt():
    if flask.request.method == 'GET':
        try:
            comment_id = flask.request.args.get('id')
            comment = Comment.query.get(comment_id)
            db.session.delete(comment)
            db.session.commit()
            return xt_json.json_result_ok('删除成功!')
        except Exception as e:
            print e
            return xt_json.json_params_error('内部错误!')
    else:
        try:
            comment_id = flask.request.form.get('id')
            comment = Comment.query.get(comment_id)
            if comment.is_live:
                comment.is_live = False
            else:
                comment.is_live = True
            db.session.commit()
            return xt_json.json_result_ok('修改成功!')
        except Exception as e:
            print e
            return xt_json.json_params_error('内部错误!')
コード例 #14
0
def save_setting():
    form = Front_setting_form(flask.request.form)
    if form.validate():
        front_user = flask.g.front_user
        if not front_user:
            return xt_json.json_server_error('数据错误!')
        relname = form.relname.data
        gender = form.gender.data
        qq = form.qq.data
        avatar = form.avatar.data
        signature = form.signature.data
        front_user.relname = relname
        front_user.gender = gender
        front_user.qq = qq
        front_user.avatar = avatar
        front_user.signature = signature
        db.session.commit()
        return xt_json.json_result_ok('设置成功!')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #15
0
def add_comment():
    form = Front_comment_form(flask.request.form)
    if form.validate():
        post_id = form.id.data
        content = form.content.data
        post = public_models.Post.query.get(post_id)
        front_user = flask.g.front_user
        comment = public_models.Comment(comtent=content,
                                        create_time=datetime.datetime.now())
        post.comments.append(comment)
        front_user.comments.append(comment)
        comment_date = datetime.date.today()
        comment_date = str(comment_date) + 'comment'
        if not LOGIN_TEMP.has_key(comment_date):
            LOGIN_TEMP[comment_date] = 1
            front_user.bbs_points += 3  # 发表二级评论积分加3
        elif LOGIN_TEMP[comment_date] <= 8:
            front_user.bbs_points += 3  # 发表二级评论积分加3
            LOGIN_TEMP[comment_date] += 1
        db.session.commit()
        return xt_json.json_result_ok('评论成功!')
    else:
        return xt_json.json_params_error(form.get_error())
コード例 #16
0
ファイル: cms_exts.py プロジェクト: mistacker/BBS
def add_edit_cms_user():
    if flask.request.is_xhr and flask.request.method == 'GET':
        id = flask.request.args.get('id')
        cms_user = CMSUser.query.get(id)
        if not cms_user.is_live:
            cms_user.is_live = True
            db.session.commit()
            return xt_json.json_result_ok('恭喜,解禁成功!')
        else:
            cms_user.is_live = False
            db.session.commit()
            return xt_json.json_result_ok('恭喜,禁用成功!')
    else:
        web_roles = flask.request.form.getlist('web_roles[]')
        id = flask.request.form.get('id')
        if not web_roles:
            return xt_json.json_params_error('对不起,必须指定分组!')
        cms_user = CMSUser.query.get(id)
        roles = []
        for web_role in web_roles:
            roles.append(CMSRole.query.get(web_role))
        cms_user.cms_roles = roles
        db.session.commit()
        return xt_json.json_result_ok('恭喜 修改成功!')