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.params_error(form.get_error())
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.params_error(form.get_error())
def dbanner(): banner_id = request.form.get('banner_id') if not banner_id: return restful.params_error(message='请传入轮播图Id!') banner = BannerModel.query.get(banner_id) if not banner: return restful.params_error(message='没有这个轮播图!') db.session.delete(banner) db.session.commit() return restful.success()
def hpost(): post_id = request.form.get("post_id") if not post_id: return restful.params_error('请传入帖子id!') post = PostModel.query.get(post_id) if not post: return restful.params_error(('没有这篇帖子!')) highlight = HighlightPostModel(post_id=post_id) db.session.add(highlight) db.session.commit() return restful.success()
def dposts(): post_id = request.form.get("post_id") if not post_id: return restful.params_error(message='请传入帖子id!') # post = PostModel.query.filter_by(id=post_id).first() post = PostModel.query.get(post_id) if not post: return restful.params_error(message='没有这篇帖子!') db.session.delete(post) db.session.commit() return restful.success()
def dboard(): form = DeleteBoardForm(request.form) if form.validate(): board_id = form.board_id.data board = BoardModel.query.filter_by(id=board_id).first() if board: db.session.delete(board) db.session.commit() return restful.success() else: return restful.params_error(message='没有这个板块') else: return restful.params_error(message=form.get_error())
def uboard(): form = UpdateBoardForm(request.form) if form.validate(): name = form.name.data board_id = form.board_id.data board = BoardModel.query.filter_by(id=board_id).first() if board: # print(board.name) board.name = name db.session.commit() return restful.success() else: return restful.params_error(message='没有这个板块!') else: return restful.params_error(message=form.get_error())
def abanner(): form = AbannerForm(request.form) if form.validate(): name = form.name.data image_b = form.image_b.data link_url = form.link_url.data priority = form.priority.data banner = BannerModel(name=name, image_b=image_b, link_url=link_url, priority=priority) db.session.add(banner) db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error())
def add_comment(): form = AddCommentForm(request.form) if form.validate(): post_id = form.post_id.data content = form.content.data post = PostModel.query.filter_by(id=post_id) if post: comment = CommentModel(content=content, post_id=post_id) comment.author = g.Front_user db.session.add(comment) db.session.commit() return restful.success() else: return restful.params_error(message='没有这篇帖子') else: return restful.params_error(message=form.get_error())
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.params_error(message='手机或密码错误!') else: return restful.params_error(form.get_error())
def post(self): form = SignupForm(request.form) if form.validate(): telephone = form.telephone.data username = form.username.data password1 = form.password1.data user = FrontUser(telephone=telephone, username=username, password=password1) db.session.add(user) db.session.commit() return restful.success() else: # message = form.get_error().popitem()[1][0] message = form.get_error() print(form.get_error()) return restful.params_error(message=message)
def cancelpraise(): form = PraiseForm(request.form) if form.validate(): post_id = form.post_id.data fuser_id = form.fuser_id.data praise = PraiseModel.query.filter_by(post_id=post_id).first() post = PostModel.query.filter_by(id=post_id).first() if praise: count = post.praise_count - 1 post.praise_count = count db.session.delete(praise) db.session.commit() return restful.success() else: return restful.params_error(message="没有这篇帖子!") else: return restful.params_error(message=form.get_error())
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 restful.success() else: return restful.params_error("旧密码错误") else: messagr = form.get_error() # print("+++++++++++") # print(messagr) # print("+++++++++++") return restful.params_error(messagr)
def ubanner(): form = UbannerForm(request.form) if form.validate(): name = form.name.data image_b = form.image_b.data link_url = form.link_url.data priority = form.priority.data banner_id = form.banner_id.data banner = BannerModel.query.get(banner_id) if banner: banner.name = name banner.image_b = image_b banner.link_url = link_url banner.priority = priority db.session.commit() return restful.success() else: return restful.params_error(message="没有这个轮播图!") else: return restful.params_error(message=form.get_error())
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.params_error(message='没有这个板块!') post = PostModel(title=title, content=content, board_id=board_id) post.author = g.Front_user db.session.add(post) db.session.commit() return restful.success() else: return restful.params_error(message=form.get_error())
def email_captcha(): email = request.args.get('email') if not email: return restful.params_error('请传递邮箱参数') #给用户输入的邮箱发送验证码 source = list(string.hexdigits) #生成0-9 a-f A-F字符串且转换为列表 captcha = "".join(random.sample(source, 6)) # message = Message("ZZ论坛邮箱验证码",recipients=[email],body="您的验证码是:%s"%captcha) #异常处理 # try: # mail.send(message) # except: # return restful.server_error() try: send_mail.delay("ZZ论坛邮箱验证码", [email], "您的验证码是:%s" % captcha) except: return restful.server_error() #讲邮箱和验证码缓存到memcached中 zzcache.set(email, captcha) return restful.success()
def sms_captcha(): form = SMSCaptchaForm(request.form) if form.validate() == 1: return restful.params_error(message='号码已存在!') if form.validate() == 2: telephone = form.telephone.data captcha = Captcha.gene_text(4) params = json.dumps({'code': captcha}) # 将 Python 对象编码成 JSON 字符串 print(params) result = demo_sms_send.send_sms(telephone, params) #发送验证码 print(type(result)) resu = str(result, encoding='utf-8') #bytes转字符串 print(resu) params2 = json.loads(resu) #JSON到字典转化 if params2['Code'] == 'OK': zzcache.set(telephone, captcha) #将验证码存入memcache return restful.success() else: # zzcache.set(telephone, captcha) # 将验证码存入memcache return restful.params_error(message='短信验证码发送失败') else: return restful.params_error(message='参数错误!!!')
def user_praise(): form = PraiseForm(request.form) if form.validate(): post_id = form.post_id.data fuser_id = form.fuser_id.data post = PostModel.query.filter_by(id=post_id).first() fuser = FrontUser.query.filter_by(id=fuser_id).first() if post and fuser: praise_pid = PraiseModel.query.filter_by(post_id=post_id).first() praise_uid = PraiseModel.query.filter_by(fuser_id=fuser_id).first() if praise_pid and praise_uid: return restful.params_error(message="用户重复点赞!") else: config.PRAISW_COUNT = config.PRAISW_COUNT + 1 now_praise = PraiseModel(fuser_id=fuser_id, post_id=post_id) post.praise_count = config.PRAISW_COUNT db.session.add(now_praise) db.session.commit() return restful.success() else: return restful.params_error(message="帖子或用户不存在") else: return restful.params_error(message=form.get_error())