def server_note(): id = request.args["id"] phone = request.args["phone"] if id and re.search(r'1[3,4,5,7,8]\d{9}', phone): for items in list(codes.keys()): for item in codes[items]: second = (datetime.now() - codes[items][item]["date"] ).seconds / 60 # 获取所有验证码存在的时间 if second >= 5: # 超过五分钟则删除 codes.pop(items) # 删除验证码 if id not in codes: code = NoetServer.random_code() code["date"] = datetime.now() codes[id] = {"code": code} # resp = eval(NoetServer(phone=phone, code_dict={"code": code}).send_code()) # if resp["Message"]=="OK": # return Success(msg="短信发送成功") else: return Success(msg="短信以发送请5分钟后重试") else: return Success(msg="电话号码格式不正确请重新输入")
def search_phone(): id = request.args["id"] uid = request.args["uid"] if id != uid: if Serch_message.search_phone(id, uid): return Success() return Success()
def edit_logs_delete(): form = CaseEditLogForm().validate_for_api() count = Case.edit_logs_remove(form.id.data, form.url.data, form.method.data, form.deal.data, form.start.data, form.end.data) if count == 0: return Success(msg='无符合条件数据') else: return Success(msg='成功删除' + str(count) + '条数据')
def case_logs_delete(): form = CaseLogsSearchForm().validate_for_api() count = Case.case_log_remove(form.name.data, form.url.data, form.project.data, form.task.data, form.result.data, form.start.data, form.end.data) if count == 0: return Success(msg='无符合条件数据') else: return Success(msg='成功删除' + str(count) + '条数据')
def delete_tasks(): form = TaskSearchForm().validate_for_api() count = Task.delete_tasks(form.user.data, form.project.data, form.no.data, form.start.data, form.end.data) if count == 0: return Success(msg='无符合条件数据') else: return Success(msg='成功删除' + str(count) + '条数据')
def update_case(cid): form = CaseForm().validate_for_api() case = Case.query.filter_by(id=cid, case_group=form.caseGroup.data, delete_time=None).first_or_404() case.edit_case(form.name.data, form.info.data, form.url.data, form.method.data, form.submit.data, form.header.data, form.data.data, form.deal.data, form.condition.data, form.expect.data, form.assertion.data, form.type.data) return Success(msg='更新用例成功')
def create_case(): form = CaseForm().validate_for_api() case = Case(form.caseGroup.data, form.name.data, form.info.data, form.url.data, form.method.data, form.submit.data, form.header.data, form.data.data, form.deal.data, form.condition.data, form.expect.data, form.assertion.data, form.type.data) case.new_case() return Success(msg='新增用例成功')
def delete_book(id): book = Book.query.filter_by(id=id).first() # 通过Book模型在数据库中查询id=`id`的书籍 if book is None: raise NotFound(msg='没有找到相关书籍') # 如果书籍不存在,返回一个异常给前端 # 删除图书,软删除 book.delete(commit=True) return Success(msg='删除图书成功')
def update(): uid = g.user.id wx_nickname = request.json['nickname'] consumer = Consumer.query.get_or_404(uid) with db.auto_commit(): consumer.wx_name = wx_nickname return Success()
def add_mock(): form = MockForm().validate_for_api() mock = Mock(form.method.data, form.url.data, form.requestHeader.data, form.requestBody.data, form.responseHeader.data, form.responseBody.data, form.statusCode.data, form.msg.data) mock.new_mock() return Success(msg='新增mock成功')
def edit_job(sid): form = SchedulerEditForm().validate_for_api() scheduler = Scheduler.query.filter_by(id=sid, delete_time=None).first() scheduler.edit_job(form.user.data, form.sendEmail.data, form.copyPerson.data, form.cron.data, form.emailStrategy.data) return Success(msg='修改成功')
def update_group(gid): form = UpdateGroup().validate_for_api() exists = manager.group_model.get(id=gid) if not exists: raise NotFound(msg='分组不存在,更新失败') exists.update(name=form.name.data, info=form.info.data, commit=True) return Success(msg='更新分组成功')
def my_collect(): id = request.args["id"] result = User.my_collect(id=id) if result: return jsonify(len(eval(result))) else: return Success()
def create_book(): """ 创建图书 """ book_schema = request.context.json Book.create(**book_schema.dict(), commit=True) return Success(12)
def create_group_file(): form = CreateGroupFile().validate_for_api() print(form.type.data, 'form.type.data') FileManage = FileMap[form.type.data] # 1 img ,2 txt,3 audio,4 video current_path = current_app.static_url_path site_domain = current_app.config.get('SITE_DOMAIN') \ if current_app.config.get('SITE_DOMAIN') else 'http://127.0.0.1:2100' replace_path = site_domain + current_path current_user = get_current_user() with db.auto_commit(): for item in form.paths.data: # real_path=item.path.replace(replace_path,'') real_path = item['path'].replace(replace_path, '') one = FileManage.query.filter_by( path=real_path, folder_id=form.folder_id.data).first() if not one: File.query.filter_by(path=real_path).update( {File.active: 1}, synchronize_session=False) FileManage.create(folder_id=form.folder_id.data, path=real_path, title=item['title'], auth_id=current_user.id) return Success(msg='添加成功')
def update_user(uid): form = UpdateUserInfoForm().validate_for_api() user = manager.user_model.get(id=uid) if user is None: raise NotFound("用户不存在") if user.email != form.email.data: exists = manager.user_model.get(email=form.email.data) if exists: raise ParameterError("邮箱已被注册,请重新输入邮箱") with db.auto_commit(): user.email = form.email.data group_ids = form.group_ids.data # 清空原来的所有关联关系 manager.user_group_model.query.filter_by(user_id=user.id).delete( synchronize_session=False) # 根据传入分组ids 新增关联记录 user_group_list = list() # 如果没传分组数据,则将其设定为 guest 分组 if len(group_ids) == 0: group_ids = [ manager.group_model.get(level=GroupLevelEnum.GUEST.value).id ] for group_id in group_ids: user_group = manager.user_group_model() user_group.user_id = user.id user_group.group_id = group_id user_group_list.append(user_group) db.session.add_all(user_group_list) return Success("操作成功")
def stop_job(): form = SchedulerOperateForm().validate_for_api() scheduler = Scheduler.query.filter_by( scheduler_id=form.schedulerId.data).first() scheduler.stop_job() return Success(msg='停止成功')
def remove_auths(): form = RemoveAuths().validate_for_api() with db.auto_commit(): db.session.query(manager.auth_model) \ .filter(manager.auth_model.auth.in_(form.auths.data), manager.auth_model.group_id == form.group_id.data) \ .delete(synchronize_session=False) return Success(msg='删除权限成功')
def add_job(): form = SchedulerForm().validate_for_api() scheduler = Scheduler() scheduler.new_job(form.project.data, form.user.data, form.sendEmail.data, form.copyPerson.data, form.cron.data, form.emailStrategy.data) return Success('新增定时任务成功')
def task_log(taskNo): logs = Case.case_log_search_all(taskNo) logs_lists = [] for log in logs: l = log_format(log) logs_lists.append(l) socket_io.emit('log', {'logs': logs_lists, 'task_no': taskNo}) return Success(msg='广播成功')
def recover_group_file(): form = DeleteOrRecoverGroupFile().validate_for_api() # 1 img ,2 txt,3 audio,4 video FileManage = FileMap[form.type.data] with db.auto_commit(): FileManage.query.filter(FileManage.id.in_(form.ids.data), ).update( {FileManage.delete_time: None}, synchronize_session=False) return Success(msg='文件已恢复')
def delete_group(bid): form = FileType().validate_for_api() FileManage = FileMap[form.type.data] hasFile = FileManage.query.filter_by(folder_id=bid).first() if hasFile: raise Forbidden(msg='文件夹下(或文件夹下的回收站)有文件不能删除') FileGroup.remove_group(bid) return Success(msg='删除文件分组成功')
def delete_openvpnuser(): form = CreateUserForm().validate_for_api() result = OpenVPNUser.delete_user(form) if result is True: command = ["/usr/local/bin/vpnuser", "del", form.username.data] command = ' '.join(str(d) for d in command) remote_server.onetime_shell(command) return Success(msg='注销成功')
def change_user_password(id): form = ResetPasswordForm().validate_for_api() user = find_user(id=id) if user is None: raise NotFound(msg='用户不存在') with db.auto_commit(): user.reset_password(form.new_password.data) return Success(msg='密码修改成功')
def create_quota(): """创建语录""" form = CreateQuotaForm().validate_for_api() Quota.create(content=form.content.data, content_text=form.content.plain_text, category_id=form.category_id.data, commit=True) return Success()
def delete_user(uid): user = manager.user_model.get(id=uid) if user is None: raise NotFound(msg='用户不存在') # user.delete(commit=True) # 此处我们使用硬删除,一般情况下,推荐使用软删除即,上一行注释的代码 user.hard_delete(commit=True) return Success(msg='操作成功')
def edit_mock(mid): form = MockForm().validate_for_api() mock = Mock(form.method.data, form.url.data, form.requestHeader.data, form.requestBody.data, form.responseHeader.data, form.responseBody.data, form.statusCode.data, form.msg.data) mock.mid = mid mock.edit_mock() return Success(msg='修改mock成功')
def register(): data = eval(str(request.data, encoding='utf-8')) form = Register(ImmutableMultiDict(data)) if form.validate(): # 数据校验 UserInfo.register_user(form) return Success(msg="注册成功") else: return form.errors
def trans2active(id): user = manager.user_model.get(id=id) if user is None: raise NotFound(msg='用户不存在') if user.is_active: raise Forbidden(msg='当前用户已处于激活状态') with db.auto_commit(): user.active = UserActive.ACTIVE.value return Success(msg='操作成功')
def dispatch_auth(): form = DispatchAuth() form.validate_for_api() one = manager.auth_model.get(group_id=form.group_id.data, auth=form.auth.data) if one: raise Forbidden(msg='已有权限,不可重复添加') meta = find_auth_module(form.auth.data) manager.auth_model.create(group_id=form.group_id.data, auth=meta.auth, module=meta.module, commit=True) return Success(msg='添加权限成功')