def debanner(): banner_id = request.form.get('banner_id') print(banner_id) if not banner_id: return restful.parames_error(message="请传入轮播图ID") banner = BannerModel.query.get(banner_id) if not banner: return restful.parames_error(message="没有这个轮播图") else: db.session.delete(banner) #如果banner 存在数据库中 就删除 db.session.commit() return restful.success()
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.parames_error("旧密码错误") else: # message = form.get_error() #获取表单验证器的错误提示 # return jsonify({"code":400,"message":message}) return restful.parames_error(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.parames_error(message="手机号码或密码错误!") else: return restful.parames_error(message=form.get_error())
def post(self): form = RestEmailForm(request.form) if form.validate(): email = form.email.data g.cms_user.email = email db.session.commit() return restful.success() else: return restful.parames_error(form.get_error())
def ubanner(): form = UpdataBannerForm(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.parames_error(message="没有这个轮播图") else: return restful.parames_error(form.get_error())
def post(self): form = SignupForm(request.form) if form.validate(): telephone = form.telephone.data username = form.username.data password = form.password1.data telephone_db = FrontUser.query.filter_by( telephone=telephone).first() if telephone_db: return restful.parames_error(message="手机号已存在") else: user = FrontUser(telephone=telephone, username=username, password=password) db.session.add(user) db.session.commit() return restful.success() else: print(form.get_error()) return restful.parames_error(message=form.get_error())
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.parames_error(form.get_error())
def sms_captcha(): form = SMSCaptchaForm(request.form) if form.validate(): telephone = form.telephone.data captcha = Captcha.gene_text(number=4) #生成4位短信验证码 print("发送的短信验证码是%s" % captcha) if alidayu.send_sms(telephone, code=captcha): zlcache.set(telephone, captcha) #将手机验证码存储到memcached种,telephone为KEY,captcha为值 return restful.success() else: #return restful.parames_error("参数错误") zlcache.set(telephone, captcha) ### 为了测试 就算阿里大于发送失败也存储到memcached return restful.success() #用于测这里设置为成功!!! else: return restful.parames_error(message="参数错误")
def Email_captcha(): email = request.args.get("email") if not email: return restful.parames_error("请输入邮箱地址!") source = list(string.ascii_letters) source.extend(map(lambda x: str(x), range(0, 10))) captcha = "".join(random.sample(source, 4)) #生成8为的随机字符当做验证码 message = Message("xmbbs邮箱验证码", recipients=[email], body='您的验证码是:%s' % captcha) try: mail.send(message) except: return "服务器异常!" #代码走到这里说明验证码已经发送成功了,将验证码写入到memecached中 zlcache.set(email, captcha) #email当做key, captcha是验证码 return restful.success("验证码发送成功!")