def post(self): id = request.form.get('id') if not id: return field.params_error(message='参数缺失') image = Images.query.get(id) if not image: return field.params_error(message='没有改图片') filename = image.name if image.type == 'github': git = GithubTools() code, message = git.delete_file('{}{}'.format( config.PATH, '/' + filename)) db.session.delete(image) db.session.commit() return field.success(message=message) elif image.type == 'server': path = os.path.join(config.LOCAL_STORAGE_PATH, filename) if os.path.exists(path): os.remove(path) db.session.delete(image) db.session.commit() return field.success(message='删除成功') else: return field.params_error(message='没有改图片') else: return field.params_error('配置文件中STORE_TYPE字段设置不正确')
def post(self): form = LoginForm(request.form) if form.validate(): email = form.email.data # 邮箱或者用户名 password = form.password.data remember = form.remember.data user = Admin.query.filter_by( email=email).first() or Admin.query.filter_by( username=email).first() if user and user.check_password(password): session[ current_app.config['CMS_USER_ID']] = user.id # 保存用户登录信息 if remember: # 如果设置session.permanent = True,那么过期时间为31天 session.permanent = True user.last_login_time = datetime.datetime.now() db.session.add(user) db.session.commit() return field.success(message='登陆成功!') else: return field.params_error(message='邮箱或者密码错误') else: message = form.get_error() return field.params_error(message=message)
def post(self): data = request.values id = data.get('id') del_ips = IPS.query.filter(IPS.id == id).first() if del_ips: db.session.delete(del_ips) db.session.commit() return field.success(message='删除成功!') return field.params_error(message='删除失败!')
def get(self): account_id = request.args.get('account_id') if account_id: account = WechatAccount.query.filter_by(__biz=account_id.strip()).first() if account: img = account.qr_code return field.success(message='查询成功', data={'img': img}) else: return field.params_error('') return field.params_error('参数错误')
def post(self): ips = request.form.get('ips') if ips: is_exc = IPS.query.filter(IPS.ips == ips).first() if not is_exc: new_ips = IPS(ips=ips) db.session.add(new_ips) db.session.commit() return field.success(message='{}添加成功!'.format(ips)) return field.params_error(message='添加失败!') return field.params_error(message='添加失败!')
def post(self): data = request.values print(data) get_id = data.get('id') status = data.get('status') ips = IPS.query.filter(IPS.id == get_id).first() if ips: if status: if ips.status != status: ips.status = status db.session.commit() return field.success(message='修改成功!') return field.params_error(message='修改失败!') return field.params_error(message='修改失败!')
def get(self): id = request.args.get('id') if id: article = WechatArticleList.query.filter_by(sn=id).first() if article: article_dict = {} article_dict['title'] = article.title if article.author == '': article_dict['author'] = '匿名' else: article_dict['author'] = article.author article_dict['publish_time'] = str(article.publish_time) article_dict['account_name'] = article.account article_dict['url'] = article.url article_dict['content_html'] = tools.filter_html(article.content_html) article_dict['id'] = getattr(article, '__biz') return field.success(message='', data=article_dict) else: return field.params_error(message='没有该文章!') return field.params_error(message='参数错误!')
def article_id(): # TODO:必须登录用户才能够查看快照功能 id = request.args.get('id') if id: article = WechatArticle.query.filter_by(sn=id).filter(WechatArticle.is_hide == 0).first() if article: article_dict = {} article_dict['title'] = article.title if article.author == '': article_dict['author'] = '匿名' else: article_dict['author'] = article.author article_dict['publish_time'] = str(article.publish_time) article_dict['account_name'] = article.account article_dict['url'] = article.url article_dict['content_html'] = tools.filter_html(article.content_html) article_dict['id'] = article.__biz return field.success(message='', data=article_dict) else: return field.params_error(message='没有该文章!') return field.params_error(message='参数错误!')